【问题标题】:Can't use MaterialTextView无法使用 MaterialTextView
【发布时间】:2019-08-28 10:57:19
【问题描述】:

我正在使用 Material 组件,但很遗憾,我无法使用 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。

【问题讨论】:

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


    【解决方案1】:

    MaterialTextView 仍处于 alpha 状态,它在1.0.0可用。要使用它,您应该

    升级到最新的材料依赖

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

    【讨论】:

      【解决方案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'
      

      【讨论】:

      • 不错。我正在使用材质 alpha09 版本
      猜你喜欢
      • 2021-01-12
      • 2021-06-21
      • 1970-01-01
      • 2021-02-05
      • 2020-07-02
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多