I'm creating a class derived from Dialog. The titlebar of the dialog looks really nice, it's a dark grey color that is somewhat transparent. Is there a way to set the color used for the background of the titlebar? The grey is cool, but I would like to set it to some custom color. I don't think this is possible, I think I'd need to supply my own stretchable background dialog resource. Is that right?
Thanks
Use the below code:
final Dialog mailDialog = new Dialog(MainActivity.this);
mailDialog.getWindow().setBackgroundDrawableResource(R.drawable.dialog_box);
And create a custom dialog box xml in drawable folder as below:
dialog_box.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<corners
android:bottomLeftRadius="5dp"
android:bottomRightRadius="5dp"
android:topLeftRadius="5dp"
android:topRightRadius="5dp" />
<gradient
android:angle="-90"
android:centerColor="#660D1E4A"
android:endColor="#66011444"
android:startColor="#66505E7F"
android:type="linear"
/>
<stroke
android:dashGap="0dp"
android:dashWidth="0dp"
android:width="1dp"
android:color="#ffffffff" />
</shape>
Hope this helps you.
You can use:
this.getWindow().setBackgroundDrawableResource(R.color.blue);
That will set the entire window color including the titlebar.
You can then change the background color for the layout of the dialog which is everything but the titlebar to whatever you like and the title bar will remain blue.
The best way is to use a custom dialog where you can then customize its look.
Have a look at Set AlertBox Title Bar Background Color and this http://developer.android.com/guide/topics/ui/dialogs.html on how to go about it.
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