Is there the possibility of creating a popup and inside it a textbox to type something?

Asked

Viewed 85 times

-3

Is it possible to create a popup and put something to be typed and two buttons, Cancel and OK? There is this possibility?

1 answer

1

Yes it is possible, see.

Obs: Response edited, because I was at work and in the rush did not notice the tags.

Install the package Nuget

Xamarin.Android.Support.V7.App;

Create a Layout, I’ll name him here as dialog_custom.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-Ló

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();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.