android - 无法使用MaterialTextView

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

当我尝试启动应用程序时,出现此错误:没有找到类 android.view.MaterialTextView。

因此我尝试使用包名称 com.google.android.material 进行指定,但在自动完成结果中 textview 没有出现。

最佳答案

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

升级到最新的 Material 依赖:

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

关于android - 无法使用MaterialTextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57690848/

相关文章:

android - 使用 token 的谷歌身份验证

android - Google Fit O Auth 失败并显示 RESULT_CANCELED,未显示权限页面

android - 如何解决 postMessage from WebView to React Native does not work for Android

java - Android:如何在 TextView 中为文本提供项目符号、换行符

java - 引用所有 TextView

css - 悬停时更改 Material 图标颜色

android - 应用程序 :layout_scrollFlags ="scroll|enterAlways" doesn't works with LinearLayout

Android - 语音识别

具有多个 TextView 的Android Eclipse线性布局不换行

flutter - 在 flutter 中实现 Material 可扩展输入芯片的最佳方法?