xml 中未检测到 TextView autoSizeTextType
TextView autoSizeTextType is not detecting in xml
我正在寻找自动更改 TextView 大小的方法。我也找到了解决方案。这是自动调整文本视图大小的官方 Doc。但我仍然无法解决它。当我粘贴 autoSizeTextType 时,它在 xml 文件中显示错误。
这是我的 xml 代码和 gradle 代码片段
myactivity.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical">
<include layout="@layout/toolbar" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:autoSizeTextType="uniform"/>
</LinearLayout>
Gradle 片段
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:support-v4:25.2.0'//Added support library
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support:design:25.2.0'
testCompile 'junit:junit:4.12'
}
此 API 只能从 API 26 级获得。
如 docs 中所述:
The Support Library 26.0 provides full support to the autosizing TextView feature on devices running Android versions prior to Android 8.0 (API level 26). The library provides support to Android 4.0 (API level 14) and higher. The android.support.v4.widget package contains the TextViewCompat class to access features in a backward-compatible fashion.
您需要将 TextView
替换为 AppCompatTextView
并将您的支持库升级到 v26.0.0 才能使用该功能。
compile 'com.android.support:support-v4:26.0.0'
别忘了将您的 buildToolsVersion
升级到 26.0.0
并将 compileSdkVersion
升级到 26
。
使用 AppCompatTextView 和 supportLibrary 26.0.1
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.AppCompatTextView
android:layout_width="match_parent"
android:layout_height="200dp"
app:autoSizeTextType="uniform" />
</LinearLayout>
我正在寻找自动更改 TextView 大小的方法。我也找到了解决方案。这是自动调整文本视图大小的官方 Doc。但我仍然无法解决它。当我粘贴 autoSizeTextType 时,它在 xml 文件中显示错误。
这是我的 xml 代码和 gradle 代码片段
myactivity.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical">
<include layout="@layout/toolbar" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:autoSizeTextType="uniform"/>
</LinearLayout>
Gradle 片段
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:support-v4:25.2.0'//Added support library
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support:design:25.2.0'
testCompile 'junit:junit:4.12'
}
此 API 只能从 API 26 级获得。
如 docs 中所述:
The Support Library 26.0 provides full support to the autosizing TextView feature on devices running Android versions prior to Android 8.0 (API level 26). The library provides support to Android 4.0 (API level 14) and higher. The android.support.v4.widget package contains the TextViewCompat class to access features in a backward-compatible fashion.
您需要将 TextView
替换为 AppCompatTextView
并将您的支持库升级到 v26.0.0 才能使用该功能。
compile 'com.android.support:support-v4:26.0.0'
别忘了将您的 buildToolsVersion
升级到 26.0.0
并将 compileSdkVersion
升级到 26
。
使用 AppCompatTextView 和 supportLibrary 26.0.1
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.AppCompatTextView
android:layout_width="match_parent"
android:layout_height="200dp"
app:autoSizeTextType="uniform" />
</LinearLayout>