AppCompatActivity 改变了我的 AlertDialog 设计

我已将我的活动更改为 appCompat 活动。我还将 AlertDialog 更改为 Android.Support.V7.App.AlertDialog。但我已经失去了以前的警报对话框设计。这就是它的样子。

https://img1.sycdn.imooc.com/653131760001dc1306470387.jpg

这就是现在的样子

https://img1.sycdn.imooc.com/6531318f000150b806540390.jpg

我到现在为止的主题是

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

但我被迫更改它,因为 appCompat 不支持 Holo 主题。所以我把它改为

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

如何使警报对话框看起来像上一个?


鸿蒙传说
浏览 119回答 2
2回答

慕桂英3389331

尝试这个:AlertDialog 对话框= new AlertDialog.Builder(new ContextThemeWrapper(context, android.R.style.Theme_Holo_Dialog));

泛舟湖上清波郎朗

如果你想让按钮可以帮助用户更容易按下,你可以构建一个带有自定义按钮的对话框并设置按钮的样式(例如在drawable文件夹上设置按钮的样式)。你可以参考以下代码:&nbsp;AlertDialog.Builder dialog = new AlertDialog.Builder(this);&nbsp; &nbsp; &nbsp; &nbsp; AlertDialog alert = dialog.Create();&nbsp; &nbsp; &nbsp; &nbsp; alert.SetTitle("Login Information");&nbsp; &nbsp; &nbsp; &nbsp; //alert.SetMessage("Complex Alert");&nbsp; &nbsp; &nbsp; &nbsp; //alert.SetIcon(Resource.Drawable.alert);&nbsp; &nbsp; &nbsp; &nbsp; LayoutInflater inflater = (LayoutInflater)this.GetSystemService(Context.LayoutInflaterService);&nbsp; &nbsp; &nbsp; &nbsp; View view = inflater.Inflate(Resource.Layout.input_layout, null);&nbsp; &nbsp; &nbsp; &nbsp; alert.SetView(view);&nbsp; &nbsp; &nbsp; &nbsp; EditText editText_name = view.FindViewById<EditText>(Resource.Id.et_name);&nbsp; &nbsp; &nbsp; &nbsp; EditText editText_pwd = view.FindViewById<EditText>(Resource.Id.et_pwd);&nbsp; &nbsp; &nbsp; &nbsp; Button button1 = view.FindViewById<Button>(Resource.Id.button1);&nbsp; &nbsp; &nbsp; &nbsp; Button button2 = view.FindViewById<Button>(Resource.Id.button2);&nbsp; &nbsp; &nbsp; &nbsp; button1.Click += delegate {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Toast.MakeText(this,"press button1!",ToastLength.Short).Show();&nbsp; &nbsp; &nbsp; &nbsp; };&nbsp; &nbsp; &nbsp; &nbsp; button2.Click += delegate {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Toast.MakeText(this, "press button2!", ToastLength.Short).Show();&nbsp; &nbsp; &nbsp; &nbsp; };&nbsp; &nbsp; &nbsp; &nbsp; //alert.SetButton("OK", (c, ev) =>&nbsp; &nbsp; &nbsp; &nbsp; //{&nbsp; &nbsp; &nbsp; &nbsp; //&nbsp; &nbsp; // Ok button click task&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; //&nbsp; &nbsp; string name = editText_name.Text;&nbsp; &nbsp; &nbsp; &nbsp; //&nbsp; &nbsp; string password = editText_pwd.Text;&nbsp; &nbsp; &nbsp; &nbsp; //&nbsp; &nbsp; Toast.MakeText(this, "name = " + name + " password= " + password, ToastLength.Long).Show();&nbsp; &nbsp; &nbsp; &nbsp; //});&nbsp; &nbsp; &nbsp; &nbsp; //alert.SetButton2("CANCEL", (c, ev) => { });&nbsp; &nbsp; &nbsp; &nbsp; 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"&nbsp;&nbsp;android:layout_width="match_parent"android:layout_height="match_parent"><EditText&nbsp;&nbsp; android:layout_width="match_parent"&nbsp; android:layout_height="wrap_content"&nbsp; android:id="@+id/et_name"&nbsp; android:hint="please input name"/><EditText&nbsp;&nbsp; android:layout_width="match_parent"&nbsp; android:layout_height="wrap_content"&nbsp; android:id="@+id/et_pwd"&nbsp; android:password="true"&nbsp; android:hint="please input password"/><LinearLayout&nbsp;&nbsp; &nbsp;android:padding="20dp"&nbsp; &nbsp; android:orientation="horizontal"&nbsp; &nbsp; android:layout_width="match_parent"&nbsp; &nbsp; android:layout_height="wrap_content"&nbsp; >&nbsp; &nbsp; <Button&nbsp;&nbsp; &nbsp; android:id="@+id/button1"&nbsp; &nbsp; &nbsp;android:text="button1"&nbsp; &nbsp; &nbsp;android:textColor="@android:color/white"&nbsp; &nbsp; &nbsp; android:layout_weight="1"&nbsp; &nbsp; &nbsp; android:layout_width="match_parent"&nbsp; &nbsp; &nbsp; android:layout_height="wrap_content"&nbsp; &nbsp; &nbsp; android:background="@drawable/defaultbutton"&nbsp; &nbsp; />&nbsp; &nbsp; <Button&nbsp; &nbsp; android:id="@+id/button2"&nbsp; &nbsp; android:layout_marginLeft="20dp"&nbsp; &nbsp; android:text="button2"&nbsp; &nbsp; android:textColor="@android:color/white"&nbsp; &nbsp; android:layout_weight="1"&nbsp; &nbsp; android:layout_width="match_parent"&nbsp; &nbsp; android:layout_height="wrap_content"&nbsp; &nbsp; android:background="@drawable/defaultbutton"&nbsp; &nbsp; /></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&nbsp; &nbsp; android:width="2dp"&nbsp; &nbsp; android:color="#ffffff" />--><corners&nbsp; android:bottomLeftRadius="20dp"&nbsp; android:bottomRightRadius="20dp"&nbsp; android:topLeftRadius="20dp"&nbsp; android:topRightRadius="20dp" /></shape>笔记:1.在文件夹中定义一个xml( defaultbutton.xml)drawable2.像这样使用:android:background="@drawable/defaultbutton"结果是:
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java