不能使用MaterialTextView

时间:2019-08-28 10:57:19

标签: android textview material-design material-components-android material-components

我正在使用Material Components,但不幸的是,我无法使用MaterialTextView。我不知道我在想什么。

在我的build.gradle文件中:

implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.google.android.material:material:1.0.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>

    <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" />

我这样定义了TextView:

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

当我尝试启动该应用程序时,出现以下错误:didn't find class android.view.MaterialTextView.

因此,我尝试通过使用软件包名称com.google.android.material进行指定,但是在自动完成结果中,不会显示textview。

2 个答案:

答案 0 :(得分:2)

您使用了错误的软件包android.view.MaterialTextView

使用:

<com.google.android.material.textview.MaterialTextView
            android:layout_width=""
            .../>

还需要版本 1.1.0 ,当前是:

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

答案 1 :(得分:1)

MaterialTextView仍处于Alpha状态,其{em>不可在1.0.0中可用。要使用它,您应该

升级到最新的物料依存关系

implementation 'com.google.android.material:material:1.1.0-alpha09'
相关问题