简体   繁体   English

如何通过按钮更改 TextView 的字体大小?

[英]How do I change the font size of TextView through a button?

I'm making a calculator app and I am trying to make it so that the CA (clear all) button resets the size of the text shown in the input and output spaces.我正在制作一个计算器应用程序,我正在尝试让 CA(全部清除)按钮重置输入和 output 空格中显示的文本的大小。 Because I set the text in the input and output spaces to autosize depending on the length of the equation and answer, the font size stays decreased on my next input and output as well.因为我将输入中的文本和 output 空格设置为根据等式和答案的长度自动调整大小,所以在我的下一个输入和 output 中字体大小保持减小。 Is there a way to make the button revert the text back to it's original size?有没有办法让按钮将文本恢复到原来的大小?

TextView for input TextView 用于输入

<TextView
            android:layout_weight="1"
            android:id="@+id/input"
            android:layout_width="match_parent"
            android:layout_height="80dp"
            android:autoSizeTextType="uniform"
            android:autoSizePresetSizes="@array/text_sizes"
            android:maxLength="10"
            android:background="@color/black"
            android:fontFamily="@font/lgc"
            android:gravity="end"
            android:ellipsize="end"
            android:padding="20dp"
            android:text=""
            android:textColor="@color/white"
            android:textSize="30sp" />

You can use setTextSize(unit, size) under button click event:您可以在按钮单击事件下使用setTextSize(unit, size)

yourTextViewID.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18f);

ReferDoc参考文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM