[英]TextView autoSizeTextType is not detecting in xml
我正在寻找自动更改TextView大小。 我也找到了解决方案。 以下是自动调整文本视图的官方文档 。 但我还是无法解决它。 当我将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'
}
使用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>
如文档中所述:
支持库26.0完全支持在Android 8.0(API级别26)之前运行Android版本的设备上自动调整TextView功能。 该库提供对Android 4.0(API级别14)及更高版本的支持。 android.support.v4.widget包中包含TextViewCompat类,以向后兼容的方式访问功能。
您需要将TextView
替换为AppCompatTextView
并将支持库升级到v26.0.0才能使用该功能。
compile 'com.android.support:support-v4:26.0.0'
不要忘记将buildToolsVersion
升级到26.0.0
并将compileSdkVersion
升级到26
。
此API仅适用于API级别26。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.