错误夸大类com.google.android.material.bottomnavigation.BottomNavigationView(材料设计)

问题描述 投票:0回答:1
  • 虽然使用Android Material Components BottomNavigationView我遇到以下错误:

由:java.lang.IllegalArgumentException:组件要求您的应用主题为Theme.AppCompat(或后代)。com.google.android.material.internal.ThemeEnforcement.checkAppCompatTheme(ThemeEnforcement.java:218)

  • 我正在使用依赖项:实现'com.google.android.material:material:1.1.0'

styles.xml:

<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

layout.xml:

<?xml version="1.0" encoding="utf-8"?>

<androidx.coordinatorlayout.widget.CoordinatorLayout 
  xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".activities.MainActivity">


        <com.google.android.material.bottomnavigation.BottomNavigationView
            android:id="@+id/btm_nav"
            style="@style/Widget.MaterialComponents.BottomNavigationView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            app:menu="@menu/bottom_nav_menu" />

    </androidx.coordinatorlayout.widget.CoordinatorLayout>

bottom_nav_menu.xml:

<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
    android:id="@+id/currentWeatherFragment"
    android:icon="@drawable/ic_today"
    android:title="Today" />
<item
    android:id="@+id/futureListWeatherFragment"
    android:icon="@drawable/ic_calendar_week"
    android:title="7 Days" />
<item
    android:id="@+id/settingsFragment"
    android:icon="@drawable/ic_settings"
    android:title="Settings" />

manifest.xml:

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="example.com.mvvmweatherforecast">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".activities.MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
  • 注意:我已经检查了菜单项和可绘制对象,并且当我使用材质组件时,我正在使用材质主题!
android material-design bottomnavigationview material-components-android
1个回答
0
投票
实现'com.google.android.material:material:'
    确保您正在使用AppCompatActivity
  1. 更改您的应用程序主题以从“材料组件”主题继承
  • 材料主题列表:

    Theme.MaterialComponents Theme.MaterialComponents.NoActionBar Theme.MaterialComponents.Light Theme.MaterialComponents.Light.NoActionBar Theme.MaterialComponents.Light.DarkActionBar Theme.MaterialComponents.DayNight Theme.MaterialComponents.DayNight.NoActionBar Theme.MaterialComponents.DayNight.DarkActionBar

    更新styles.xml:

    <style name="Theme.MyApp" parent="Theme.MaterialComponents.DayNight"> </style> More Info

    我希望这会有所帮助。
  • © www.soinside.com 2019 - 2024. All rights reserved.