0

I have change my activity to appCompat Activity. Also i changed AlertDialog to Android.Support.V7.App.AlertDialog. But i have lost my previous alertdialog design. This is how it was look like.

enter image description here

And this is how it looks now enter image description here My theme till now was

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

But i was enforced to changed it cause appCompat doesn't support Holo theme. So i change it to

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

How can i make alert dialog look like previous one?

haldo
  • 14,512
  • 5
  • 46
  • 52
DmO
  • 357
  • 2
  • 14
  • 1
    The style you're seeing is indeed the correct Material style you'd expect when using AppCompat. You shouldn't be using the old holo themed dialog style. – ianhanniballake Oct 13 '19 at 21:30
  • The old holo themed dialog was deprecated long back, it's better not to use it anymore – FreakyAli Oct 14 '19 at 05:12
  • Thank you for your answers, I am using it cause it has big buttons, and help user for easier press. – DmO Oct 14 '19 at 06:23

2 Answers2

2

Try this:

AlertDialog dialog= new AlertDialog.Builder(new ContextThemeWrapper(context, android.R.style.Theme_Holo_Dialog));

elchicho44
  • 138
  • 7
  • Thank you it works. But it also said that is obolete: deprecated. – DmO Oct 13 '19 at 20:13
  • Is there something Similar? – DmO Oct 13 '19 at 20:13
  • I'd suggest you build a dialog with custom buttons and stuff.Give it a little touch of your imagination ;) Basically design the layout of dialog in xml and then inflate that and assign it to Alert Dialog. Take a look at this https://stackoverflow.com/a/18353260/10243423 -- or you could use libraries 1) https://github.com/PatilShreyas/MaterialDialog-Android 2) https://github.com/Shashank02051997/FancyAlertDialog-Android – elchicho44 Oct 14 '19 at 08:00
1

if you want to make buttons could help user for easier press, you can build a dialog with custom buttons and style the Button(e.g.style the Button on drawable folder).You can refer to the following code:

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

The 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>

define a xml(e.g. defaultbutton.xml) in folder 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>

Note:

1.define a xml( defaultbutton.xml) in folder drawable

2.use like this:

android:background="@drawable/defaultbutton"

The result is:

enter image description here

Jessie Zhang -MSFT
  • 9,830
  • 1
  • 7
  • 19