材料设计不是造型警报对话框 [英] Material Design not styling alert dialogs
问题描述
我已经添加了appCompat材料设计到我的应用程序,它似乎警报对话框不使用我的小学,primaryDark,或口音的颜色。
这是我的基本样式:
<样式名称=MaterialNavyTheme父=@风格/ Theme.AppCompat.Light.DarkActionBar>
<项目名称=colorPrimary> @色/ apptheme_color< /项目>
<项目名称=colorPrimaryDark> @色/ apptheme_color_dark< /项目>
<项目名称=colorAccent> @色/ apptheme_color< /项目>
<项目名称=机器人:textColorPrimary> @色/ action_bar_gray< /项目>
< /风格>
根据我的理解对话框按钮上的文字也应该使用这些颜色。我错在我的理解还是有更多的东西,我需要做什么?
解决方法:
被标记的答案让我在正确的轨道。
<样式名称=MaterialNavyTheme父=@风格/ Theme.AppCompat.Light.DarkActionBar>
<项目名称=colorPrimary> @色/ apptheme_color< /项目>
<项目名称=colorPrimaryDark> @色/ apptheme_color_dark< /项目>
<项目名称=colorAccent> @色/ apptheme_color< /项目>
<项目名称=机器人:actionModeBackground> @色/ apptheme_color_dark< /项目>
<项目名称=机器人:textColorPrimary> @色/ action_bar_gray< /项目>
<项目名称=sdlDialogStyle> @风格/ DialogStyleLight< /项目>
<项目名称=机器人:seekBarStyle> @风格/ SeekBarNavyTheme< /项目>
< /风格>
<样式名称=StyledDialog父=Theme.AppCompat.Light.Dialog>
<项目名称=colorPrimary> @色/ apptheme_color< /项目>
<项目名称=colorPrimaryDark> @色/ apptheme_color_dark< /项目>
<项目名称=colorAccent> @色/ apptheme_color< /项目>
< /风格>
随着新的 AppCompat v22.1
您可以使用新的<一个href="http://developer.android.com/reference/android/support/v7/app/AlertDialog.html">android.support.v7.app.AlertDialog.
只需使用code是这样的:
进口android.support.v7.app.AlertDialog
AlertDialog.Builder建设者=
新AlertDialog.Builder(这一点,R.style.AppCompatAlertDialogStyle);
builder.setTitle(对话);
builder.setMessage(Lorem存有悲......);
builder.setPositiveButton(OK,NULL);
builder.setNegativeButton(取消,NULL);
builder.show();
和使用样式是这样的:
&LT;样式名称=AppCompatAlertDialogStyle父=Theme.AppCompat.Light.Dialog.Alert&GT;
&LT;项目名称=colorAccent&GT;#FFCC00&LT; /项目&GT;
&LT;项目名称=机器人:textColorPrimary&GT;#FFFFFF&LT; /项目&GT;
&LT;项目名称=机器人:背景&GT;#5fa3d0&LT; /项目&GT;
&LT; /风格&GT;
否则,你可以在你的当前主题定义:
&LT;样式名称=AppTheme父=Theme.AppCompat.Light&GT;
&LT;! - 你的风格 - &GT;
&LT;项目名称=alertDialogTheme&GT; @风格/ AppCompatAlertDialogStyle&LT; /项目&GT;
&LT; /风格&GT;
,然后在code:
进口android.support.v7.app.AlertDialog
AlertDialog.Builder建设者=
新AlertDialog.Builder(本);
下面的AlertDialog上奇巧:
I've added the appCompat material design to my app and it seems that the alert dialogs are not using my primary, primaryDark, or accent colors.
Here is my base style:
<style name="MaterialNavyTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/apptheme_color</item>
<item name="colorPrimaryDark">@color/apptheme_color_dark</item>
<item name="colorAccent">@color/apptheme_color</item>
<item name="android:textColorPrimary">@color/action_bar_gray</item>
</style>
Based on my understanding the dialogs button text should also use these colors. Am I wrong on my understanding or is there something more I need to do?
Solution:
The marked answer got me on the right track.
<style name="MaterialNavyTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/apptheme_color</item>
<item name="colorPrimaryDark">@color/apptheme_color_dark</item>
<item name="colorAccent">@color/apptheme_color</item>
<item name="android:actionModeBackground">@color/apptheme_color_dark</item>
<item name="android:textColorPrimary">@color/action_bar_gray</item>
<item name="sdlDialogStyle">@style/DialogStyleLight</item>
<item name="android:seekBarStyle">@style/SeekBarNavyTheme</item>
</style>
<style name="StyledDialog" parent="Theme.AppCompat.Light.Dialog">
<item name="colorPrimary">@color/apptheme_color</item>
<item name="colorPrimaryDark">@color/apptheme_color_dark</item>
<item name="colorAccent">@color/apptheme_color</item>
</style>
With the new AppCompat v22.1
you can use the new android.support.v7.app.AlertDialog.
Just use a code like this:
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();
And use a style like this:
<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>
and then in your code:
import android.support.v7.app.AlertDialog
AlertDialog.Builder builder =
new AlertDialog.Builder(this);
Here the AlertDialog on Kitkat:
这篇关于材料设计不是造型警报对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!