Reputation: 83
I am trying to show an AlertDialog in android. The problem is that the title of the dialog appears 2 times. I want it to show only one title? How can I do it?
That is how the dialog looks like
And that is how i show the dialog
AlertDialog alertDialog = new AlertDialog.Builder(this, android.R.style.Theme_Material_Dialog).create();
alertDialog.setTitle(R.string.ttl_alrt_dlg_dont_asked_again);
alertDialog.setMessage("AI bifat nu ma mai intreba asa ca mergi in setari");
alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
actv.finish();
//ActivityCompat.requestPermissions(actv,
// new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
// MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);
}
});
alertDialog.show();
Upvotes: 1
Views: 829
Reputation: 79
Faced a similar issue while using AppCompatDialogFragment. Ended up using as below to avoid, title showing up twice:
<style name="dialogfrag_title" parent="Theme.MaterialComponents.Light.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="android:padding">@dimen/lyt_margin</item>
<item name="android:windowBackground">@color/appBackground</item>
</style>
along with below line in the fragment class.
getDialog().setTitle("About "+ user.name());
Upvotes: 0
Reputation: 21043
Its look like its due to android.R.style.Theme_Material_Dialog
, First title is ActionBar
.
Solutions
1. Just use it without style . It will show in material design appearance anyway .
2. Or you can use android.R.style.Theme_Material_Dialog_NoActionBar
AlertDialog alertDialog = new AlertDialog.Builder(this, android.R.style.Theme_Material_Dialog_NoActionBar).create();
alertDialog.setTitle(R.string.ttl_alrt_dlg_dont_asked_again);
alertDialog.setMessage("AI bifat nu ma mai intreba asa ca mergi in setari");
alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alertDialog.show();
Upvotes: 1
Reputation: 4123
It's Theme_Material_Dialog issue. so you have to customize your own dialog by creating style.
see this helpful answer here
And this complete answer another_here
Upvotes: 0
Reputation: 5011
Try this:
AlertDialog alertDialog = new AlertDialog.Builder(this)
.setTitle("title")
.setMessage("AI bifat nu ma mai intreba asa ca mergi in setari")
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialog.dismiss();
actv.finish();
}
})
.create();
alertDialog.show();
Upvotes: 2
Reputation: 1445
Remove this line-:
alertDialog.setTitle(R.string.ttl_alrt_dlg_dont_asked_again);
Upvotes: 0