I have implemented the dialog in my app. But the title in the dialog by default in the left side. How can I make the dialog title in the center?
Here is my code
final Dialog dialog = new Dialog(getActivity());
dialog.setContentView(R.layout.contact_query);
dialog.setTitle("Query Form");
You can try this:
// Creating the AlertDialog with a custom xml layout (you can still use the default Android version)
AlertDialog.Builder builder = new AlertDialog.Builder(this);
LayoutInflater inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.viewname, null);
builder.setView(view);
TextView title = new TextView(this);
// You Can Customise your Title here
title.setText("Custom Centered Title");
title.setBackgroundColor(Color.DKGRAY);
title.setPadding(10, 10, 10, 10);
title.setGravity(Gravity.CENTER);
title.setTextColor(Color.WHITE);
title.setTextSize(20);
builder.setCustomTitle(title);
*Try this one *
Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.yourlayout);
TextView titleView = (TextView)dialog.findViewById(android.R.id.title);
titleView.setGravity(Gravity.CENTER);
For more information http://kodecenter.com/article?id=2390ec63-63d7-4534-a76f-cc3b10497a2c
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With