I am using Mono Android (Xamarin); I will show you another alternative that I use in my application to create a dialog in a fragment:
Dialog itemDialog = new Dialog(this.Activity); TextView alertTitle=(TextView)itemDialog.Window.DecorView.FindViewById(Android.Resource.Id.Title); alertTitle.SetTextColor(Android.Graphics.Color.Blue); alertTitle.SetBackgroundColor(Android.Graphics.Color.Orange); itemDialog.SetContentView(Resource.Layout.listview_custom_dialog); string[] options = new string[] { "Open", "Mark as Unread","Mute","View Profile","Block Connection","Delete Conversation" }; ArrayAdapter<string> adapter = new ArrayAdapter<string>(this.Activity, Resource.Layout.listitem_custom_dialog,Resource.Id.textViewDialogDescription, options);
Resource.Layout.listitem_custom_dialog: this is a custom list layout, here is the XML file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/transparent" > <TextView android:id="@+id/textViewDialogDescription" android:layout_width="match_parent" android:layout_height="44dp" android:background="#ffffff" android:textColor="#386B96" android:paddingLeft="4dp" android:textSize="14dp" /> </RelativeLayout> ListView lv = itemDialog.FindViewById<ListView> (Resource.Id.listViewDialogItems); lv.Adapter = adapter; adapter.NotifyDataSetChanged(); itemDialog.SetCancelable(true); itemDialog.SetTitle("Conversation"); itemDialog.Show();
Android.Resource.Id.Title : this is the identifier of the text field containing the title of the dialog. and it is predetermined by android. this way you get a dialog that you can create as you want.
Desire aheza
source share