SoulRayder
SoulRayder

Reputation: 5166

Using AlertDialog style of Kitkat on Lollipop based phones

I have the same app running perfectly on both Lollipop based android phone as well as a Jellybean based android phone. However the alert dialog styles ( default) are not the same, and the dialog appear ugly in Lollipop phones.

A simple example:

In Jellybean based phone :

In Jellybean based phone

In Lollipop based phone :

In Lollipop based phone

Is it possible for me to use the alert dialog styles of older Android OS on my Lollipop based phones?

How to do this in the app programmatically?

Upvotes: 2

Views: 2657

Answers (3)

Rohit Suthar
Rohit Suthar

Reputation: 2693

If you want Lollipop Dialog into your Pre-Lollipop Device, then you have to use android.support.v7.app.AlertDialog instead of android.app.AlertDialog

AlertDialog.Builder builder = new AlertDialog.Builder(activity);

And if you want to use Pre-Lollipop AlertDialog into Lollipop Device, then you have to use following themes:

  • AlertDialog.THEME_TRADITIONAL
  • AlertDialog.THEME_HOLO_DARK
  • AlertDialog.THEME_HOLO_LIGHT
  • AlertDialog.THEME_DEVICE_DEFAULT_DARK
  • AlertDialog.THEME_DEVICE_DEFAULT_LIGHT

and use:

AlertDialog.Builder builder = new AlertDialog.Builder(activity, theme);

Upvotes: 5

Floern
Floern

Reputation: 33904

You can specify the Dialog's theme by setting the second constructor parameter of your AlertDialog or AlertDialog.Builder to AlertDialog.THEME_HOLO_LIGHT:

new AlertDialog.Builder(context, AlertDialog.THEME_HOLO_LIGHT);

Upvotes: 3

Tran Vinh Quang
Tran Vinh Quang

Reputation: 595

Try this

AlertDialog.Builder builder = new AlertDialog.Builder(activity, AlertDialog.THEME_HOLO_LIGHT);

Hope it OK

Upvotes: 2

Related Questions