Error : IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents

前端 未结 5 859
迷失自我
迷失自我 2020-11-29 08:00

Below are my dependencies

implementation \'com.google.android.material:material:1.0.0\'
implementation \'androidx.appcompat:appcompat:1.0.2\'
implementation          


        
相关标签:
5条回答
  • 2020-11-29 08:29

    We have change Gradle dependencies and style code my case working fine

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
        <item name="android:activatedBackgroundIndicator">@drawable/drawer_list_selector</item>
        <item name="android:textColorSecondary">@color/black_overlay</item>
        <!--<item name="android:windowBackground">@drawable/nav_menu_background</item>-->
    </style>
    

    Gradle Dependencies

    implementation 'com.google.android.material:material:1.1.0-alpha06'
    
    0 讨论(0)
  • 2020-11-29 08:35

    Extend your base app Theme from Material Components Bridge theme. It extends AppCompat theme, but add all necessary stuff.

    <style name="Theme.MyApp" parent="Theme.MaterialComponents.Light.Bridge">
        <!-- ... -->
    </style>
    

    Both Theme.MaterialComponents and Theme.MaterialComponents.Light have .Bridge themes:

    Theme.MaterialComponents.Bridge
    Theme.MaterialComponents.Light.Bridge
    Theme.MaterialComponents.NoActionBar.Bridge
    Theme.MaterialComponents.Light.NoActionBar.Bridge
    Theme.MaterialComponents.Light.DarkActionBar.Bridge

    If allows you to keep using latest version of the library, but avoid a lot of UI issues, caused by migration to pure Material Component theme

    https://material.io/develop/android/docs/getting-started/#bridge-themes

    0 讨论(0)
  • 2020-11-29 08:41

    None of these worked for me. Must do these two things.

    <style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
            <!-- Customize your theme -->
    </style>
    

    and

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/nav_view"
        app:theme="@style/Theme.MaterialComponents"
    
    0 讨论(0)
  • 2020-11-29 08:47

    There is some issue with material:1.1.0-alpha01

    A simple solution is to change the parent theme

    <style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
            <!-- Customize your theme here. -->
           
    </style>
    

    Hope this helps someone else

    0 讨论(0)
  • 2020-11-29 08:47

    |> 1: Define the following style in style.xml:

    <style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
            <!-- Customize your theme -->
    </style>
    

    |> 2: In the manifest.xml file, use from above style:

    <application
        android:hardwareAccelerated="true"
        android:icon="@drawable/icon"
        android:label="@string/app_name"
        android:theme="@style/AppTheme"> <!-- IMPORTANT (This was my mistake) -->
    </application>
    

    |> 3: Choose a style for your component:

    <com.google.android.material.bottomappbar.BottomAppBar
            android:id="@+id/bottomBar"
            style="@style/Widget.MaterialComponents.BottomAppBar"
    ...
    >
    </com.google.android.material.bottomappbar.BottomAppBar>
    
    0 讨论(0)
提交回复
热议问题