使用AppCompat-v7 22进行对话框蒙皮会导致api<上的丑陋阴影21岁 [英] Dialog skinning with AppCompat-v7 22 results in ugly shadows on api < 21

查看:77
本文介绍了使用AppCompat-v7 22进行对话框蒙皮会导致api<上的丑陋阴影21岁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用AppCompat编写材料设计样式的应用程序.由于AppCompat不会影响对话框,因此我将对话框的外观设置为这样:

I'm using AppCompat to write a material design styled app. Since AppCompat does not affect dialogs, I'm skinning the dialogs as such:

styles.xml:

styles.xml:

<style name="AppTheme.Base" parent="Theme.AppCompat">
    <!-- Set AppCompat’s color theming attrs -->
    <item name="colorPrimary">@color/green</item>
    <item name="colorPrimaryDark">@color/green_darker</item>
    <item name="colorAccent">@color/accent</item>

    <item name="android:alertDialogTheme">@style/alertDialog</item>
    <item name="android:dialogTheme">@style/alertDialog</item>
</style>

<style name="alertDialog" parent="Theme.AppCompat.Dialog">
    <item name="colorPrimary">@color/green</item>
    <item name="colorPrimaryDark">@color/green_darker</item>
    <item name="colorAccent">@color/accent</item>
</style>

我得到的正是我在android api> = 21上想要的东西,但是在其他设备上,我却在对话框周围出现了一个框".

I am gettings exactly what I wanted on android api >= 21, but on other devices I end up with a "box" around the dialogs.

有没有一种方法可以消除对话框周围的框",甚至可以将颜色和材质主题应用于api< 21,最好没有其他后裔吗?

Is there a way to get rid of the "box" around the dialog and even get the colors and material theme applied on api < 21, preferably without any additional depencendies?

Api上的应用< 21:

App on Api < 21:

API上的应用程序> = 21:

App on API >= 21:

推荐答案

使用新的AppCompat v22.1,您可以使用新的android.support.v7.app.AlertDialog 或新的

With the new AppCompat v22.1 you can use the new android.support.v7.app.AlertDialog or the new AppCompatDialog

只需使用这样的代码(当然,在这种情况下,您必须使用自定义布局才能显示进度条)

Just use a code like this (of course in your case you have to use a custom layout to have the progress bar)

import android.support.v7.app.AlertDialog

AlertDialog.Builder builder =
       new AlertDialog.Builder(this, R.style.AppCompatAlertDialogStyle);
            builder.setTitle("Dialog");
            builder.setMessage("Lorem ipsum dolor ....");
            builder.setPositiveButton("OK", null);
            builder.setNegativeButton("Cancel", null);
            builder.show();

并使用如下样式:

<style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
        <item name="colorAccent">#FFCC00</item>
        <item name="android:textColorPrimary">#FFFFFF</item>
        <item name="android:background">#5fa3d0</item>
    </style>

这篇关于使用AppCompat-v7 22进行对话框蒙皮会导致api&lt;上的丑陋阴影21岁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆