【发布时间】:2021-05-09 14:36:55
【问题描述】:
com.google.android.material.bottomnavigation.BottomNavigationView 膨胀崩溃 开始出现在一些设备上。
崩溃日志:
Caused by java.lang.IllegalArgumentException
The style on this component requires your app theme to be Theme.AppCompat (or a descendant).
com.google.android.material.internal.ThemeEnforcement.checkTheme (ThemeEnforcement.java:243)
com.google.android.material.internal.ThemeEnforcement.checkAppCompatTheme (ThemeEnforcement.java:213)
com.google.android.material.internal.ThemeEnforcement.checkCompatibleTheme (ThemeEnforcement.java:148)
com.google.android.material.internal.ThemeEnforcement.obtainTintedStyledAttributes (ThemeEnforcement.java:115)
com.google.android.material.bottomnavigation.BottomNavigationView. (BottomNavigationView.java:160)
com.google.android.material.bottomnavigation.BottomNavigationView. (BottomNavigationView.java:133)
源代码:
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/navView"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:elevation="8dp"
<.. app:itemIconTint and itemTextColor colors are set >
app:labelVisibilityMode="labeled"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
主题: 我的应用主题由 Theme.MaterialComponents.Light 扩展。文件(https://github.com/material-components/material-components-android/blob/master/docs/getting-started.md#bridge-themes)说你应该使用 桥主题以支持材料组件。 我无法更改我的基本应用主题。 这是崩溃的原因吗?
所以我的问题是 -
我可以为 BottomnavigationView 定义自定义主题,它会扩展 Theme.MaterialComponents.Light.Bridge ..
<style name="bottomNav" parent="Theme.MaterialComponents.Light.Bridge"> </style>
like this 并在 bottomNavigationView 中使用该样式
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/navView"
android:layout_width="0dp"
android:layout_height="wrap_content"
style="@style/bottomNav"
/>
这会解决我的问题吗?为什么? 2. 还有其他方法吗?
【问题讨论】:
标签: android material-design material-components-android