问题描述
我用 ActionBarActivity 从Android 5 SDK,这里是我的 theme.xml 的为V21
I'm using ActionBarActivity from the Android 5 SDK and here is my theme.xml for v21
<style name="AppTheme_Light" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:colorPrimary">@color/abc1</item>
<item name="android:colorPrimaryDark">@color/abc2</item>
<item name="android:colorAccent">@color/abc3</item>
</style>
但颜色会被忽略,并通过默认的水鸭色的更换,所有的对话框出现没有填充。
But the colors are ignored, and are replaced by a default teal color and all the dialogs appear without padding.
此外,填充,也忽略了在其他地方,如自定义敬酒,问题只发生在棒棒糖设备。
Also, padding is also ignored in other places like custom toast, problem only occurs in lollipop devices.
编辑:
的填充问题是由于 fitsSystemWindow
,我得到它固定使用
<一href="http://stackoverflow.com/questions/26599805/android-alert-dialog-not-styled-properly-on-lollipop?rq=1">this问题。。
The padding problem was due to fitsSystemWindow
and I got it fixed using
this question..
但强调色的问题依然存在,而且它不只是影响对话,但是整个应用程序。
But the accent color problem is still there, and it does not just affect dialogs but the whole app.
推荐答案
关于强调色。您正在使用AppCompat主题,所以你应该从你的主题内部的名称空间中删除的Android。
About the accent color. You are using a AppCompat theme so you should remove Android from the namespace inside your theme.
<style name="AppTheme_Light" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/abc1</item>
<item name="colorPrimaryDark">@color/abc2</item>
<item name="colorAccent">@color/abc3</item>
</style>
关于对话框。 AppCompat不支持它(我知道)。
你可以尝试使用这种风格在你的值-V21 的文件夹:
About the dialog. AppCompat doesn't support it (as I know).
You can try to use this style in your values-v21 folder:
<style name="Theme" parent="FrameworkRoot.Theme">
<item name="android:alertDialogTheme">@style/Theme.AlertDialog</item>
</style>
<style name="Theme.AlertDialog" parent="android:Theme.Material.Light.Dialog.Alert">
<item name="android:colorPrimary">@color/demo_primary_color</item>
<item name="android:colorPrimaryDark">@color/demo_colorPrimaryDark</item>
<item name="android:colorAccent">@color/theme_accent_1</item>
</style>
更新23/04/2015:支持库V.22.1
新支持库v22.1
工作原理与对话。您可以使用android.support.v7.app.AlertDialog或新的AppCompatDialog.
The new support library v22.1
works with the Dialog.You can use an android.support.v7.app.AlertDialog or the new AppCompatDialog.
例如:
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>
否则,你可以在你的当前主题定义:
Otherwise you can define in your current theme:
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- your style -->
<item name="alertDialogTheme">@style/AppCompatAlertDialogStyle</item>
</style>
,然后在code:
and then in your code:
import android.support.v7.app.AlertDialog
AlertDialog.Builder builder =
new AlertDialog.Builder(this);
这篇关于Android的V21 Theme.Appcompat颜色口音被忽略,在对话框中没有填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!