【发布时间】:2017-12-23 16:02:59
【问题描述】:
我已经配置了一个对话框在第一次使用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" />
【问题讨论】:
标签: android xml android-studio button dialog