AppCompatActivity изменила мой дизайн AlertDialog - PullRequest
0 голосов

Я изменил свою активность на appCompat Activity. Также я изменил AlertDialog на Android.Support.V7.App.AlertDialog. Но я потерял свой предыдущий дизайн. Вот так это выглядело.

enter image description here

А вот так это выглядит сейчас enter image description here Моя тема до сих пор была

parent="@android:style/Theme.Holo.Light.DarkActionBar">

Но я был вынужден изменить его, потому что appCompat не поддерживает тему Holo. Поэтому я изменяю его на

 parent="Theme.AppCompat.Light.DarkActionBar">

Как мне сделать диалог оповещения похожим на предыдущий?

Ответы [ 2 ]

1 голос
/ 14 октября 2019

если вы хотите, чтобы кнопки могли помочь пользователю для более легкого нажатия, вы можете создать диалог с пользовательскими кнопками и стилизовать кнопку (например, стиль кнопки в папке для рисования). Вы можете обратиться к следующему коду:

 AlertDialog.Builder dialog = new AlertDialog.Builder(this);
        AlertDialog alert = dialog.Create();
        alert.SetTitle("Login Information");
        //alert.SetMessage("Complex Alert");
        //alert.SetIcon(Resource.Drawable.alert);

        LayoutInflater inflater = (LayoutInflater)this.GetSystemService(Context.LayoutInflaterService);
        View view = inflater.Inflate(Resource.Layout.input_layout, null);
        alert.SetView(view);

        EditText editText_name = view.FindViewById<EditText>(Resource.Id.et_name);
        EditText editText_pwd = view.FindViewById<EditText>(Resource.Id.et_pwd);

        Button button1 = view.FindViewById<Button>(Resource.Id.button1);
        Button button2 = view.FindViewById<Button>(Resource.Id.button2);

        button1.Click += delegate {

            Toast.MakeText(this,"press button1!",ToastLength.Short).Show();
        };

        button2.Click += delegate {
            Toast.MakeText(this, "press button2!", ToastLength.Short).Show();
        };

        //alert.SetButton("OK", (c, ev) =>
        //{
        //    // Ok button click task  
        //    string name = editText_name.Text;
        //    string password = editText_pwd.Text;
        //    Toast.MakeText(this, "name = " + name + " password= " + password, ToastLength.Long).Show();
        //});
        //alert.SetButton2("CANCEL", (c, ev) => { });
        alert.Show();

input_layout.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">
<EditText 
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:id="@+id/et_name"
  android:hint="please input name"
/>
<EditText 
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:id="@+id/et_pwd"
  android:password="true"
  android:hint="please input password"
/>

<LinearLayout 
   android:padding="20dp"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"  >

    <Button 
    android:id="@+id/button1"
     android:text="button1"
     android:textColor="@android:color/white"
      android:layout_weight="1"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:background="@drawable/defaultbutton"
    />
    <Button
    android:id="@+id/button2"
    android:layout_marginLeft="20dp"
    android:text="button2"
    android:textColor="@android:color/white"
    android:layout_weight="1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/defaultbutton"
    />
</LinearLayout>

определяют XML (например, defaultbutton.xml) в папке drawable

<?xml version="1.0" encoding="utf-8" ?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#1E90FF" />
<!--<stroke
    android:width="2dp"
    android:color="#ffffff" />-->
<corners
  android:bottomLeftRadius="20dp"
  android:bottomRightRadius="20dp"
  android:topLeftRadius="20dp"
  android:topRightRadius="20dp" />
</shape>

Примечание:

1. Определить XML (defaultbutton.xml) в папке drawable

2.Используйте так:

android:background="@drawable/defaultbutton"

Результат:

enter image description here

1 голос
/ 13 октября 2019

Попробуйте это:

Диалог AlertDialog = новый AlertDialog.Builder (новый ContextThemeWrapper (context, android.R.style.Theme_Holo_Dialog));

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...