Android TextView autoSizeTextType在Compat中不工作
我尝试使用了Android TextView autoSizeTextType在Compat中不工作,android,xml,textview,android-support-library,Android,Xml,Textview,Android Support Library,我尝试使用了autoSizeTextType。 我的minSdk是24,所有工具都是26,而且compatist 26-beta2也是如此 通过以下代码尝试使其可调: dialogWeight.touchables.filterIsInstance<Button>().forEach { TextViewCompat.setAutoSizeTextTypeWithDefaults(it, TextViewCompat.AUTO_SIZE_TEXT_TYPE_UNIFORM) }
autoSizeTextType
。
我的minSdk是24,所有工具都是26,而且compatist 26-beta2也是如此
通过以下代码尝试使其可调:
dialogWeight.touchables.filterIsInstance<Button>().forEach {
TextViewCompat.setAutoSizeTextTypeWithDefaults(it,
TextViewCompat.AUTO_SIZE_TEXT_TYPE_UNIFORM) }
dialogWeight.touchables.filterIsInstance().forEach{
TextViewCompat.setAutoSizeTextTypeWithDefaults(它,
TextViewCompat.AUTO_SIZE_TEXT_TYPE_UNIFORM)}
和xml:
<android.support.v7.widget.AppCompatTextView
android:layout_height="match_parent"
android:text="7"
android:autoSizeTextType="uniform"/>
有什么想法吗?我开始相信它现在被窃听了好的,所以设置组合起作用了:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v7.widget.AppCompatTextView
android:text="7"
app:autoSizeTextType="uniform"/>
我通过编程解决了这个问题
TextView number1=findviewbyd(R.id.number\u-one);
TextViewCompat.setAutoSizeTextTypeWithDefaults(数字1,TextViewCompat.AUTO_SIZE_TEXT_TYPE_UNIFORM);
以及XML:
<TextView
android:id="@+id/number_one"
android:autoSizeTextType="uniform"
android:gravity="center"
android:text="1" />
要理解的关键是使用
应用程序:autoSizeTextType
,而不是android:autoSizeTextType
根据:
要通过支持库在XML中定义默认设置,请使用应用程序名称空间,并将autoSizeTextType属性设置为none或uniform
我想更新这个线程,因为android.support.v7已经迁移到androidX 我在显示文本时遇到了一些问题,而解决问题的是其中一条评论中关于单线的注释:
请注意,请确保不要设置android:singleLine=“true”,否则自动收缩将无法工作
您是否也可以发布build.gradle的相关内容,其中包括兼容性部分,因为我在这方面遇到了问题。另外,Android Studio编辑器是否在app:autosizetextype=“uniform”
行中显示任何错误?您是否能够以编程方式将appcompatitextview
作为TextView
进行处理?我也有同样的问题。要正确使用AppCompatTextView
和TextViewCompat
,您应该将support-v4(com.android.support:support-v4:27.0.1)和appcompat-v7(com.android.support:appcompat-v7:27.0.1)包含到构建梯度中。确保将
xml标记更改为
。希望能对您有所帮助:)@nanangarsyad appcompat-v7将support-v4作为依赖项安装。您只需要在build.gradle文件中使用appcompat-v7。另请注意,确保不要设置android:singleLine=“true”
,否则自动收缩将无法工作。同时设置autoSizeMinTextSize
,否则会应用默认值,文本可能会在末尾被截断。
<TextView
android:id="@+id/number_one"
android:autoSizeTextType="uniform"
android:gravity="center"
android:text="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">
<TextView
android:layout_width="match_parent"
android:layout_height="200dp"
app:autoSizeTextType="uniform" />
</LinearLayout>
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tempText"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:maxLines="1"
android:textColor="@color/white"
android:textSize="60dp"
app:autoSizeMinTextSize="20dp"
app:autoSizeTextType="uniform"
tools:text="99°" />