I\'m developing an Android application.
How can I center the title for a custom dialog that I\'m using?
You can do it programmatically without custom view:
@Override
public void onStart()
{
super.onStart();
TextView textViewVanilla = (TextView) this.getDialog().findViewById(android.R.id.title);
if(textViewVanilla != null)
{
textViewVanilla.setGravity(Gravity.CENTER);
}
// support for appcompat v7
TextView textViewAppcompat = (TextView) this.getDialog().findViewById(android.support.v7.appcompat.R.id.alertTitle);
if(textViewAppcompat != null)
{
textViewAppcompat.setGravity(Gravity.CENTER);
}
}
Thanks @hesam for the idea. For appcompat layout see Android/sdk/platforms/android-26/data/res/layout/alert_dialog_title_material.xml