Dialog.setTitle not showing a title

十年热恋 提交于 2019-12-03 05:44:07

you should define your style like this:

 <style name="Dialog" parent="Theme.AppCompat.Dialog">
    <item name="android:windowNoTitle">false</item>
    <item name="android:windowIsFloating">true</item>
</style>

and then pass this style to the constructor of the Dialog

final Dialog passwordDialog = new Dialog(this,R.style.Dialog);

Like the other answer, but more concise

final AlertDialog diag = new AlertDialog.Builder(this)
        .setTitle("Enter An Administrative Password")
        .setView(R.layout.admin_password_dialog)
        .create();

diag.show();

Button diagButton = (Button) diag.findViewById(R.id.btn_confirmPassword);
diagButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        // handle button click
        EditText input = (EditText) diag.findViewById(R.id.edit_adminPassword);
        String s = input.getText().toString();
    }
});

You can try this method as well and get different view styles based upon theme used.

<style name="FilterDialogTheme" parent="@android:style/Theme.Holo.Light.Dialog">
    <item name="android:windowNoTitle">false</item>
</style>

In Dialog constructor

  public FilterDialog(Context context) {
        super(context, R.style.FilterDialogTheme);
    }

Use @style/Theme.Appcompat.Light.Dialog for your project.

You should use an AlertDialog.Builder instead of just creating a Dialog:

// 1. Instantiate an AlertDialog.Builder with its constructor
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

// 2. Chain together various setter methods to set the dialog characteristics
builder.setView(R.layout.admin_password_dialog);
builder.setTitle("Enter An Administrative Password");

// 3. Get the AlertDialog from create()
AlertDialog dialog = builder.create();
dialog.show();

See here for the Android Developers Guide on Dialogs.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!