作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已将 android 应用程序设置为使用 Material 主题
<style name="AppTheme" parent="AppTheme.Base"></style>
<style name="AppTheme.Base" parent="Theme.MaterialComponents.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
<item name="android:textColorSecondary">@android:color/white</item>
<item name="android:textColorHint">@android:color/darker_gray</item>
<item name="searchViewStyle">@style/SearchViewStyle</item>
</style>
new MaterialAlertDialogBuilder(mAppContext)
.setTitle("Title")
.setMessage("Message")
.setPositiveButton("Ok", null)
.show();
java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.AppCompat (or a descendant).
at com.google.android.material.internal.ThemeEnforcement.checkTheme(ThemeEnforcement.java:240)
at com.google.android.material.internal.ThemeEnforcement.checkAppCompatTheme(ThemeEnforcement.java:211)
at com.google.android.material.internal.ThemeEnforcement.checkCompatibleTheme(ThemeEnforcement.java:146)
at com.google.android.material.internal.ThemeEnforcement.obtainStyledAttributes(ThemeEnforcement.java:78)
at com.google.android.material.dialog.MaterialDialogs.getDialogBackgroundInsets(MaterialDialogs.java:55)
at com.google.android.material.dialog.MaterialAlertDialogBuilder.<init>(MaterialAlertDialogBuilder.java:116)
at com.google.android.material.dialog.MaterialAlertDialogBuilder.<init>(MaterialAlertDialogBuilder.java:102)
at com.syl.app.fragments.AlarmNotificationDetailFragment$2.onClick(UserFragment.java:265)
at android.view.View.performClick(View.java:5207)
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:941)
at android.view.View$PerformClick.run(View.java:21177)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5441)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)
MaterialAlertDialogBuilder requires that your application use a Material Components theme (e.g., Theme.MaterialComponents.Light). Using a Material Components theme with MaterialAlertDialogBuilder will result in an AlertDialog that matches your appplication’s color, typography, and shape theming.
最佳答案
只需使用 即可
Context context = new ContextThemeWrapper(SelectImageActivity.this, R.style.AppTheme2);
MaterialAlertDialogBuilder dialogBuilder = new MaterialAlertDialogBuilder(context);
<style name="AppTheme2" parent="Theme.MaterialComponents.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimaryDark</item>
<item name="colorPrimaryDark">@color/yellow</item>
<item name="colorAccent">@color/yellow</item>
</style>
关于android - 将 MaterialAlertDialogBuilder 与 Material 主题一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57100308/
我是一名优秀的程序员,十分优秀!