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. 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. Is there a way to make the button revert the text back to it's original size?
TextView for input
<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" />
-
I'm using android studio20Lcola– 20Lcola2020年05月18日 03:34:15 +00:00Commented May 18, 2020 at 3:34
1 Answer 1
You can use setTextSize(unit, size) under button click event:
yourTextViewID.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18f);
Refer Doc
answered May 18, 2020 at 3:42
Lakshitha
1,5601 gold badge12 silver badges20 bronze badges
Sign up to request clarification or add additional context in comments.
4 Comments
20Lcola
It doesn't seem to work even after I put in original values for the size
20Lcola
btnClear.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { input.setText(""); output.setText(""); input.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30); output.setTextSize(TypedValue.COMPLEX_UNIT_SP, 70); } });
Lakshitha
TextView mytextView = (TextView) findViewById(R.id.yourTextViewID); mytextView .setTextSize(TypedValue.COMPLEX_UNIT_SP, 18f);
20Lcola
The fontsize still stay decreased, I included the code for the TextView in my main post.
lang-java