So in my app I have a welcome layout or a help layout that shows you how the app works and what it can do, I would like it to only be displayed once when the app is installed and then never show again. And if this is possible what's the easiest way to do it?
Asked
Active
Viewed 379 times
1 Answers
1
You can try something like this. Create two layouts. Your main layout and your tutorial layout to overlay on top of your main view. Have a method to check if its the first time and show the tutorial layout if it is the first time. If it is not the first time, set the tutorial layout as invisible.
isFirstTime() Method
private boolean isFirstTime()
{
SharedPreferences preferences = getPreferences(MODE_PRIVATE);
boolean ranBefore = preferences.getBoolean("RanBefore", false);
if (!ranBefore) {
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("RanBefore", true);
editor.commit();
topLevelLayout.setVisibility(View.VISIBLE);
topLevelLayout.setOnTouchListener(new View.OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event) {
topLevelLayout.setVisibility(View.INVISIBLE);
return false;
}
});
}
return ranBefore;
}
Layout XML
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/main_layout" >
<!--Below activity widgets when the transparent layout is gone -->
<RelativeLayout
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/gradient">
<include
android:id="@+id/include1"
layout="@layout/actionbar" />
<ImageView
android:id="@+id/ivDressshirt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tvLength"
android:layout_marginTop="55dp"
android:paddingLeft="@dimen/padding10dp"
android:src="@drawable/shirt" />
</RelativeLayout>
<!--Below is the transparent layout positioned at startup -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#88666666"
android:id="@+id/top_layout">
<ImageView
android:id="@+id/ivInstruction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:paddingTop="25dp"
android:layout_marginRight="15dp"
android:clickable="false"
android:paddingLeft="20dip"
android:scaleType="center"
android:src="@drawable/help" />
</RelativeLayout>
</FrameLayout>
onCreate()
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
topLevelLayout = findViewById(R.id.top_layout);
if (isFirstTime()) {
topLevelLayout.setVisibility(View.INVISIBLE);
}

erad
- 1,766
- 2
- 17
- 26