[英]TextView autoSizeTextType is not detecting in xml
I'm looking for changing the TextView Sizes automatically. 我正在寻找自动更改TextView大小。 And I found the solution as well. 我也找到了解决方案。 Here is the official Doc for Auto sizing textviews. 以下是自动调整文本视图的官方文档 。 But Still I'm not able to resolve it. 但我还是无法解决它。 When i paste autoSizeTextType its showing error in xml file. 当我将autoSizeTextType粘贴到xml文件中时显示错误。
Here is the my xml code and gradle code snippets 这是我的xml代码和gradle代码片段
myactivity.xml 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 snippet 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'
}
Use AppCompatTextView and supportLibrary 26.0.1 使用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>
As stated in the 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). 支持库26.0完全支持在Android 8.0(API级别26)之前运行Android版本的设备上自动调整TextView功能。 The library provides support to Android 4.0 (API level 14) and higher. 该库提供对Android 4.0(API级别14)及更高版本的支持。 The android.support.v4.widget package contains the TextViewCompat class to access features in a backward-compatible fashion. android.support.v4.widget包中包含TextViewCompat类,以向后兼容的方式访问功能。
You need to replace TextView
with AppCompatTextView
and upgrade your support lib to v26.0.0 in order to use that feature. 您需要将TextView
替换为AppCompatTextView
并将支持库升级到v26.0.0才能使用该功能。
compile 'com.android.support:support-v4:26.0.0'
Don't forget to upgrade your buildToolsVersion
to 26.0.0
and compileSdkVersion
to 26
as well. 不要忘记将buildToolsVersion
升级到26.0.0
并将compileSdkVersion
升级到26
。
此API仅适用于API级别26。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.