Search code examples
androidtextviewmaterial-designmaterial-components-androidmaterial-components

Can't use MaterialTextView


I'm using Material Components but unfortunately, I can't use MaterialTextView. I don't know what I'm missing.

In my build.gradle file:

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

And in 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>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.MaterialComponents.Dark.ActionBar" />

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.MaterialComponents.Light" />

I defined my TextView like this:

<MaterialTextView android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Some text"
            android:textStyle="bold" />

When I tried to launch the app, I get this error: didn't find class android.view.MaterialTextView.

So I tried to specify by using the package name com.google.android.material but in the autocomplete result textview doesn't appear.


Solution

  • MaterialTextView is still in alpha state its not available in 1.0.0. To use it you should

    Upgrade to the latest material dependency :

    implementation 'com.google.android.material:material:1.1.0-alpha09'