Mat*_*hew 160 android android-appcompat android-support-library material-design material-components-android
我已将appCompat材质设计添加到我的应用程序中,似乎警报对话框未使用我的primary,primaryDark或强调颜色.
这是我的基本风格:
<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>
Run Code Online (Sandbox Code Playgroud)
根据我的理解,对话框按钮文本也应该使用这些颜色.我的理解是错的还是我还需要做些什么?
解:
明确的答案让我走上正轨.
<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>
Run Code Online (Sandbox Code Playgroud)
Gab*_*tti 455
使用新的,com.google.android.material.dialog.MaterialAlertDialogBuilder
您可以使用新的 android.support.v7.app.AlertDialog.
只需使用这样的代码:
new MaterialAlertDialogBuilder(context)
.setTitle("Dialog")
.setMessage("Lorem ipsum dolor ....")
.setPositiveButton("Ok", /* listener = */ null)
.setNegativeButton("Cancel", /* listener = */ null)
.show();
Run Code Online (Sandbox Code Playgroud)
并使用这样的风格:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light">
...
<item name="materialAlertDialogTheme">@style/ThemeOverlay.MaterialComponents.MaterialAlertDialog</item>
</style>
Run Code Online (Sandbox Code Playgroud)
否则,您可以在当前主题中定义:
new MaterialAlertDialogBuilder(context, R.style.ThemeOverlay_MaterialComponents_MaterialAlertDialog)
Run Code Online (Sandbox Code Playgroud)
然后在你的代码中:
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();
Run Code Online (Sandbox Code Playgroud)
这里是Kitkat上的AlertDialog:
初始化对话框构建器时,将第二个参数作为主题传递.它将自动显示API级别为21的材料设计.
AlertDialog.Builder builder = new AlertDialog.Builder(this, AlertDialog.THEME_DEVICE_DEFAULT_DARK);
Run Code Online (Sandbox Code Playgroud)
要么,
AlertDialog.Builder builder = new AlertDialog.Builder(this, AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
95036 次 |
最近记录: |