Center Message in AlertDialog vertically

nikossaperasnikossaperas USMember
edited January 2017 in Xamarin.Android

Hello,

I am new to xamarin- I want to display a validation Alert Dialog with the error message centered vertically.That is,in the image provided the literal "Maximum mumber of prefered.." beeing at the center of the dialog not at the top.

I currently do it as such:

        var builder = new AlertDialog.Builder(this.context);

        var inflater = ((Activity)this.context).LayoutInflater;

        var dialogView = inflater.Inflate(Resource.Layout.showmessagefragment, null);

        var messageTextView = dialogView.FindViewById<TextView>(Resource.Id.textview_Message);
        messageTextView.Text = this.message;

        builder.SetView(dialogView);
        builder.SetPositiveButton("OK", HandlePositiveButtonClick);
        builder.SetNegativeButton("Cancel", HandleNegativeButtonClick);

        var dialog = builder.Create();

        this.dialog = dialog;

And showmessagefragment is

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:gravity="center_vertical"
    android:background="#000000">
    <TextView
        android:id="@+id/textview_Message"
        android:textColor="#FFFFFF"
        android:gravity="center"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>

Any help is more than welcome.
Thank you

Answers

  • gtlealgtleal ✭✭ BRMember ✭✭

    Hi. Try this on your TextView:

    <TextView
            android:id="@+id/textview_Message"
            android:textColor="#FFFFFF"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    
  • nikossaperasnikossaperas USMember

    Thank you very much for the response.
    No ,unfortunately wrap_content and no gravity set did not aligned the text in the center.

  • gtlealgtleal ✭✭ BRMember ✭✭

    I think the text is vertically centered. The white part is the footer of AlertDialog, the view you created occupies the black space.

Sign In or Register to comment.