Android material chip component crashing app. Unable to inflate xml

前端 未结 4 1915
既然无缘
既然无缘 2020-11-29 08:53

Tried Chip component from both support library
com.google.android.support:design:28.0.0-rc01 and material
com.google.an

相关标签:
4条回答
  • 2020-11-29 09:36

    Add the following new theme attributes to your existing app theme:

    <style name="Theme.MyApp" parent="Theme.AppCompat">
    
        <!-- Original AppCompat attributes. -->
        <item name="colorPrimary">@color/my_app_primary_color</item>
        <item name="colorPrimaryDark">@color/my_app_primary_dark_color</item>
        <item name="colorAccent">@color/my_app_accent_color</item>
    
        <!-- New MaterialComponents attributes. -->
        <item name="colorSecondary">?attr/colorPrimary</item>
        <item name="scrimBackground">@color/mtrl_scrim_color</item>
        <item name="textAppearanceHeadline1">@style/TextAppearance.MaterialComponents.Headline1</item>
        <item name="textAppearanceHeadline2">@style/TextAppearance.MaterialComponents.Headline2</item>
        <item name="textAppearanceHeadline3">@style/TextAppearance.MaterialComponents.Headline3</item>
        <item name="textAppearanceHeadline4">@style/TextAppearance.MaterialComponents.Headline4</item>
        <item name="textAppearanceHeadline5">@style/TextAppearance.MaterialComponents.Headline5</item>
        <item name="textAppearanceHeadline6">@style/TextAppearance.MaterialComponents.Headline6</item>
        <item name="textAppearanceSubtitle1">@style/TextAppearance.MaterialComponents.Subtitle1</item>
        <item name="textAppearanceSubtitle2">@style/TextAppearance.MaterialComponents.Subtitle2</item>
        <item name="textAppearanceBody1">@style/TextAppearance.MaterialComponents.Body1</item>
        <item name="textAppearanceBody2">@style/TextAppearance.MaterialComponents.Body2</item>
        <item name="textAppearanceCaption">@style/TextAppearance.MaterialComponents.Caption</item>
        <item name="textAppearanceButton">@style/TextAppearance.MaterialComponents.Button</item>
        <item name="textAppearanceOverline">@style/TextAppearance.MaterialComponents.Overline</item>
    
    </style>
    

    Source: https://material.io/develop/android/docs/getting-started/
    Thanks @Paranoid42

    0 讨论(0)
  • 2020-11-29 09:37

    Update your app theme to inherit from one of these themes:

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

    For example:

    <style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
    

    Note: Using a Material Components theme enables a custom view inflater

    Source: https://www.material.io/develop/android/docs/getting-started/

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

    Finally Got a solution as how to generate chips dynamically using new material chips

    Google has not provided any documentation for chipsInput layout or how to make a gmail address like layout. Using ChipDrawable won't give delete operation on chip option as can't call setOnCloseIconClickListener. I was able to do using HorizontalScrollView, ChipGroup and EditText

    Here's my code sample :

    MaterialChipsInputDemo

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

    You can juste add @style/Theme.MaterialComponents.Light style attribut in xml layout like this:

    <com.google.android.material.chip.Chip
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="chip"
    android:theme="@style/Theme.MaterialComponents.Light"/>
    
    0 讨论(0)
提交回复
热议问题