在xml中未检测到TextView autoSizeTextType

Man*_*mar 6 xml android textview android-support-library

我正在寻找自动更改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>
Run Code Online (Sandbox Code Playgroud)

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'
}
Run Code Online (Sandbox Code Playgroud)

Ali*_*Rak 9

使用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>
Run Code Online (Sandbox Code Playgroud)


Joe*_*n93 6

文档中所述:

支持库26.0完全支持在Android 8.0(API级别26)之前运行Android版本的设备上自动调整TextView功能.该库提供对Android 4.0(API级别14)及更高版本的支持.android.support.v4.widget包中包含TextViewCompat类,以向后兼容的方式访问功能.

您需要更换TextViewAppCompatTextView升级您的支持lib添加到v26.0.0才能使用该功能.

compile 'com.android.support:support-v4:26.0.0'
Run Code Online (Sandbox Code Playgroud)

不要忘记升级你的buildToolsVersionto 26.0.0compileSdkVersionto 26.

  • 做了所有步骤.同样的问题`错误:(17)在包com.package.abc中找不到属性'autoSizeTextType'的资源标识符` (3认同)