gpt4 book ai didi

android - 如何以编程方式将 autoSizeTextType 统一?

转载 作者:行者123 更新时间:2023-12-05 00:16:39 37 4
gpt4 key购买 nike

这是可以做到的

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autoSizeTextType="uniform"
android:maxLines="1" />

但是属性 autoSizeTextType 只能用于 API LEVEL >= 26,并且 Android Studio 会显示有关该问题的烦人警告。

为了摆脱这个问题,我想以编程方式做到这一点,但有 3 种方法:

textView.setAutoSizeTextTypeUniformWithPresetSizes(...)
textView.setAutoSizeTextTypeUniformWithConfiguration(...)

这两个需要配置,但我想成为默认配置,与android:autoSizeTextType="uniform"相同。

textView.setAutoSizeTextTypeWithDefaults(TextView.AUTO_SIZE_TEXT_TYPE_UNIFORM);

这说:

AppCompatTextView.setAutoSizeTextTypeWithDefaults can only be called from within the same library group (groupId=com.android.support).

PS:我将代码包装成:

if(android.os.Build.VERSION.SDK_INT= > 26) {...}

最佳答案

您可以使用TextViewCompat类来避免库限制错误。就像,

TextViewCompat.setAutoSizeTextTypeWithDefaults(textView,TextViewCompat.AUTO_SIZE_TEXT_TYPE_UNIFORM);

关于android - 如何以编程方式将 autoSizeTextType 统一?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56251729/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com