Is it possible to create a popup and inside it a textbox to type something?

-3

There is the possibility of creating a popup and putting something to be typed and two buttons, Cancel and OK? Is there such a possibility?

    
asked by anonymous 25.10.2017 / 09:43

1 answer

1

Yes it is possible, see.

  

Obs : Edited answer, since I was at work and in the rush I did not notice the tags.

Install the Nuget package

Xamarin.Android.Support.V7.App;

Create a Layout , I'll name it here as dialog_personalizado.xml

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
    <TextView
        android:id="@+id/dialogTitulo"
        android:layout_width="wrap_parent"
        android:layout_height="wrap_parent"
        android:text="Titulo do Dialog"
        android:textAppearance="?android:attr/textAppearanceLarge" />
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_parent"
        android:hint="Digite um texto!"
        android:id="@+id/editText1" />
</LinearLayout>

Here the code to run it

LayoutInflater layoutInflaterAndroid = LayoutInflater.From(this);
View mView = layoutInflaterAndroid.Inflate(Resource.Layout.dialog_personalizado, null);
Android.Support.V7.App.AlertDialog.Builder alertBuilder = new Android.Support.V7.App.Builder(this);
alertBuilder.setView(mView);

var userTexto = mVIew.FindViewById<EditText>(Resource.Id.editText1);
alertBuilder.SetCancelable(false)
.SetPositiveButton("Enviar", delegate {
        Toast.MakeText(this, "Texto enviado: " + userTexto.Text, ToastLength.Short).Show();
})
.SetNegativeButton("Cancelar", delegate {
    alertBuilder.Dispose();
});

Android.Support.V7.App.AlertDialog alertDialog = alertBuilder.Create();
alertDialog.Show();
    
25.10.2017 / 09:50