0

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" />
asked May 18, 2020 at 3:12
1
  • I'm using android studio Commented May 18, 2020 at 3:34

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

4 Comments

It doesn't seem to work even after I put in original values for the size
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); } });
TextView mytextView = (TextView) findViewById(R.id.yourTextViewID); mytextView .setTextSize(TypedValue.COMPLEX_UNIT_SP, 18f);
The fontsize still stay decreased, I included the code for the TextView in my main post.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.