android - 由于 Material TextView,Android 资源链接失败
问题描述
我想在我的 android 应用程序中使用材料设计。所以我在我的项目中添加了这个依赖:implementation 'com.android.support:design:27.1.1'
. 我有相同的compileSdkVersion
和targetSdkVersion
as27
并且也使用相同版本的AppCompat
Library: implementation 'com.android.support:appcompat-v7:27.1.1'
。我也有谷歌的 Maven 存储库:
allprojects {
repositories {
google()
jcenter()
}
}
此外,我的活动扩展AppCompatActivity
并且我有父主题,AppCompat
如<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
. styles.xml
尽管我满足所有这些条件,但当我将材料TextView
放入时xml
:
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="textfield_label">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>
我在设计预览中看到了无法识别的类型视图。此外,应用程序在尝试启动时停止。
解决方案
您有 2 个选项:
- 使用组件
com.google.android.material.textfield.TextInputLayout
- 使用组件
android.support.design.widget.TextInputLayout
对于第一个选项,您必须为Android导入Material Components而不是 Design Support Library。
Android 的 Material Components 是 Android 设计支持库的直接替代品。
对于第二个选项,只需更改使用的组件:
<android.support.design.widget.TextInputLayout
...>
<android.support.design.widget.TextInputEditText />
</android.support.design.widget.TextInputLayout>
对于 android 的材料组件,您必须添加新库:
dependencies {
// ...
implementation 'com.google.android.material:material:<version>'
// ...
}
并检查设置的文档(您必须更改 compileSdkVersion、依赖项和主题),还必须迁移到 androidx 库。
请记住:
注意:随着 Android 9.0(API 级别 28)的发布,有一个名为 AndroidX 的支持库的新版本,它是 Jetpack 的一部分。AndroidX 库包含现有的支持库,还包含最新的 Jetpack 组件。
我们建议在所有新项目中使用 AndroidX 库
推荐阅读
- javascript - 将时间段从 API 转换为选定的时区
- c++ - 尝试使用 Boost gil 读取图像时出错
- python - 谷歌云平台 int64_field_0
- javascript - 在 moment.js 中比较 24 小时格式时间
- r - 尝试将图像添加到我的 RMarkdown 但出现错误
- tensorflow - 如果一个工作进程稍后关闭会话,则 tensorflow 工作进程会以集群模式挂起
- javascript - Javascript - Undefined Array of input field values on Enter click
- microsoft-teams - 在 Teams Apps 中创建撰写扩展时出现错误
- tensorflow - graph_pb2.GraphDef 和 tf.GraphDef 的区别
- android - Android configChanges 方向