【问题标题】:Create custom dialog while app running first time in Android [duplicate]在Android中首次运行应用程序时创建自定义对话框[重复]
【发布时间】:2014-08-26 14:55:31
【问题描述】:

MainActivity 类,退出按钮点击事件:

 public void onClick(View v) {

    CustomDialog cd = new CustomDialog();
    dialog = new Dialog(this);
    cd.runConfirmationDialog(dialog, R.layout.custommessage,
    R.id.d_tittle, "Exit", R.id.d_text, "Close Application",
    R.id.btn_no, R.id.btn_yes, this);


    }

自定义对话框类:

public class CustomDialog extends Activity {

void runConfirmationDialog(final Dialog dialog, int customLayoutID,int titleID, String title, int messageID, String message, int buttonCancelID,
        int buttonOkeyID, final CustomDialogMethods main) {

    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(customLayoutID);


}

void show(){

}

现在,我想在应用程序首次运行时使用 runConfirmationDialog 方法创建自定义对话框。在我想在另一个类中显示只有简单显示方法的对话框之后。

哪种方式最适合它?

谢谢。

【问题讨论】:

  • 你应该先学习 android 基础知识:什么是 Activity 以及如何启动它(以及为什么我不应该在扩展 Activity 类的类上调用 new 运算符)然后学习如何在 android 平台上使用对话框学习如何使用共享偏好...在此之前,每个答案都像是试图向盲人描述彩虹...

标签: android customdialog


【解决方案1】:

我认为最好的方法是在 SharedPreferences 上保存一个布尔值,指示对话框是否已显示:

public static void setFirstRunDialogShown(Context context, boolean value) {
    Editor editor = context.getSharedPreferences(SETTINGS_NAME, Context.MODE_PRIVATE).edit();
    editor.putBoolean(DIALOG_SHOWN, value);
    editor.apply();
}

public static boolean isFirstRunDialogShown(Context context) {
    return context.getSharedPreferences(SETTINGS_NAME, Context.MODE_PRIVATE).getBoolean(DIALOG_SHOWN, false);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-24
    • 2011-11-25
    • 2023-03-09
    • 1970-01-01
    • 2014-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多