无法在xml中检测到TextView autoSizeTextType [英] TextView autoSizeTextType is not detecting in xml

查看:71
本文介绍了无法在xml中检测到TextView autoSizeTextType的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找自动更改 TextView 大小的方法.我也找到了解决方案.这是用于自动调整文本视图大小的官方 Doc .但是我仍然无法解决它.当我将autoSizeTextType粘贴到xml文件中时,显示错误.

I'm looking for changing the TextView Sizes automatically. 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.

这是我的xml代码和gradle代码片段

Here is the my xml code and gradle code snippets

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>

渐变片段

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'
}

推荐答案

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

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,才能使用该功能.

You need to replace TextView with AppCompatTextView and upgrade your support lib to v26.0.0 in order to use that feature.

compile 'com.android.support:support-v4:26.0.0'

别忘了将buildToolsVersion升级到26.0.0,并且将compileSdkVersion升级到26.

Don't forget to upgrade your buildToolsVersion to 26.0.0 and compileSdkVersion to 26 as well.

这篇关于无法在xml中检测到TextView autoSizeTextType的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆