在基于 Lollipop 的手机上使用 Kitkat 的 AlertDialog 风格

Using AlertDialog style of Kitkat on Lollipop based phones

我在基于 Lollipop android phone 和基于 Jellybean 的 android phone 上完美地拥有相同的应用程序 运行。然而,警告对话框样式(默认)不一样,并且对话框在 Lollipop phones 中显得很丑陋。

一个简单的例子:

基于 Jellybean phone :

基于 Lollipop phone :

我可以在基于 Lollipop 的 phone 上使用旧 Android OS 的警报对话框样式吗?

如何以编程方式在应用程序中执行此操作?

试试这个

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

希望一切顺利

您可以通过将 AlertDialogAlertDialog.Builder 的第二个构造函数参数设置为 AlertDialog.THEME_HOLO_LIGHT:

来指定对话框的主题
new AlertDialog.Builder(context, AlertDialog.THEME_HOLO_LIGHT);

如果您想将 Lollipop Dialog 加入您的 Pre-Lollipop 设备,则必须使用 android.support.v7.app.AlertDialog 而不是 android.app.AlertDialog

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

如果您想在 Lollipop 设备中使用 Pre-Lollipop AlertDialog,则必须使用以下主题:

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

并使用:

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