簡體   English   中英

如何制作我自己的自定義對話框

[英]how to make my own custom dialog box

我已經下載了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();

}

非常感謝。

這是一個示例,您可以在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());

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM