I am creating a custom dialog and I want to know how to change the background of the title bar.
I've tried two approaches:
1 - I've tried the AlertDialog.Builder method 'setCustomTitle'. I created a simple layout view comprising of a textview with layout width and height 'match_parent' and background color. When I run the app, only the top half of the title bar is showing the background color. The bottom half is still showing the default theme background color. Does anyone know why?
2 - I've created my own dialog theme. Ive created a style with parent inheritance to '@android:style/Theme.Holo.Light.Dialog'. I've then passed that in the AlertDialog.Builder constructor - new AlertDialog.Builder(this, R.style.test_dialog). It seems good but somehow the dialog is wrapped within a dialog. A square box is surrounding the dialog. Does anyone know why?
The dialog-wrapped-within-a-dialog appearance is caused by the dialog's window background. Every dialog has this, but the default Android dialogs have the window background set to transparent. To do this, add this item in your custom dialog theme:
Create an xml layout file for your title and inflate it and set to to the AlertDialog as
I am using Mono Android(Xamarin); am showing you another alternative that am using in my app to create a dialog in a fragment:
Resource.Layout.listitem_custom_dialog: this is custom listview layout, here is the xml file:
Android.Resource.Id.Title: this is the id of the textview containing the dialog title. and it is predefined by android. this way you will get a dialog that you can style in way you want.
You can create a style like,
And you can instantiate dialog:
Now the dialog shows up with black title background color.
You can just set custom title like this
and in custom_title layout you can create custom title like this