【问题标题】:how to make my own custom dialog box如何制作我自己的自定义对话框
【发布时间】:2015-02-13 14:16:33
【问题描述】:

我已经下载了 AppRate (https://github.com/TimotheeJeannin/AppRate) 并使用它来提示一个对话框,要求用户在特定的启动次数和时间过去后对应用程序进行评分。到目前为止它工作正常.. 唯一的事情是,我想将它与定制的布局(在 XML 文件上制作)合并,这样对话框看起来会与标准应用程序主题不同。 这有可能吗?


代码:

private void showDefaultDialog() {

    Log.d(TAG, "Create default dialog.");

    String title = "Rate " + getApplicationName(hostActivity.getApplicationContext());
    String message = "If you enjoy using " + getApplicationName(hostActivity.getApplicationContext()) + ", please take a moment to rate it. Thanks for your support!";
    String rate = "Rate it !";
    String remindLater = "Remind me later";
    String dismiss = "No thanks";

    new AlertDialog.Builder(hostActivity)
            .setTitle(title)
            .setMessage(message)
            .setPositiveButton(rate, this)
            .setNegativeButton(dismiss, this)
            .setNeutralButton(remindLater, this)
            .setOnCancelListener(this)
            .create().show();

}

非常感谢。

【问题讨论】:

标签: android layout dialog rate


【解决方案1】:

这是一个例子,你可以在 custom_dialog.xml 中写任何你想要的东西

public class CustomDialog extends DialogFragment {

public CustomDialog() {

}

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Dialog dialog = new Dialog(getActivity());
    LayoutInflater inflater = getActivity().getLayoutInflater();
    View view = inflater.inflate(R.layout.custom_dialog, null);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(view);
    dialog.setCancelable(true);

    return dialog;
}

}

为了显示对话框,请使用此代码

CustomDialog dialog = new CustomDialog();
dialog.show(context, CustomDialog.class.getName());

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多