java - 如何更改 AutoTextSize(最大和最小)

标签 java android

如何在 Android Studio 中通过 java 代码更改 AutoTextSize(最大值和最小值)。

    TextView versesText;
    versesText = findViewById(R.id.VersesArabicTashkeel);
    versesText.setAutoSizeTextTypeUniformWithConfiguration(5, 25 ,1,1);
    //versesText.setAutoSizeTextTypeUniformWithConfiguration(5, 25 ,0,0);

我想将最大值设置为 25,将最小值设置为 5,在其他代码中,我需要将最大值更改为 20,将最小值更改为 5

应用因之前的代码而崩溃

最佳答案

您使用的这段代码 versesText.setAutoSizeTextTypeUniformWithConfiguration(5, 25, 1, 1); 是完全错误的。引用官方documentation正确使用它。文档明确指出:

define a range of text sizes and a dimension programmatically through the support library, call the TextViewCompat.setAutoSizeTextTypeUniformWithConfiguration(int autoSizeMinTextSize, int autoSizeMaxTextSize, int autoSizeStepGranularity, int unit) method. Provide the maximum value, the minimum value, the granularity value, and any TypedValue dimension unit.

所以,你应该使用如下的东西:

TextViewCompat.setAutoSizeTextTypeUniformWithConfiguration(5, 25, 1, 1);

此外,如果您还没有包含以下内容,请检查它们:

The Support Library 26.0 provides full support to the auto sizing TextView feature on devices running Android versions prior to Android 8.0 (API level 26).

由于 Support Library 26 现已移至 Google 的 Maven 存储库, 将其包含在您的项目级别 build.gradle 中:

buildscript {

   repositories {
       google()
   }
   ....
}

并在您的应用级 build.gradle 中添加支持库:

dependencies {
   ....
   implementation 'com.android.support:support-v4:26.0.2'

}

关于java - 如何更改 AutoTextSize(最大和最小),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50091660/

相关文章:

java - 提升跟踪登录用户

android - 设置 Activity 的标题栏名称

android - 在其他 Activity 中使用 On Button Click Listener 时出错

Android:当应用程序处于后台时,有什么方法可以从显着运动传感器收集数据吗?

java - 覆盖 System.out/err.println

java - AbstractList.add() 不支持的操作

java - DCL 还坏吗?

java - 指定类文件目的地

android asyncTask 对话框圆

java - 将文件另存为音频文件后无法播放