0
アンドロイドアプリの初めての使用時に表示されるダイアログを設定しました。このダイアログにはボタンがあります。ボタンを送信するとこのダイアログを非表示にする方法 ここに私のコードダイアログボタン初めてのAndroidアプリの使用
MainActivityコード
private boolean isFirstTime() {
SharedPreferences preferences = getPreferences(MODE_PRIVATE);
boolean ranBefore = preferences.getBoolean("RanBefore", false);
if (!ranBefore) {
//show dialog if app never launch
dialog.show();
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("RanBefore", true);
editor.commit();
}
return !ranBefore;
}
//Create Dialog
dialog = new Dialog(MainActivity.this);
dialog.setContentView(R.layout.dialog_user);
//method call
user_dialogレイアウト
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:gravity="center"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="453dp"
android:background="@null"
android:src="@drawable/first_login" />
</LinearLayout>
<Button
android:id="@+id/btnok"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="20dip"
android:text="OK, GOT IT"
android:background="@null"
android:textColor="#0000FF"
android:textSize="20sp" />
once click on OK,GOT IT to be dimess
ここで私はMainActivity内のダイアログを呼び出しますが、別のxmlの中にダイアログを実装しています –
@ Demon.r updated answer – Curio