-1

This is my editText:

      <EditText
                android:id="@+id/max_deep_bin"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:digits="0123456789"
                android:foregroundGravity="center"
                android:singleLine="true"
                android:gravity="center"
                android:inputType="numberDecimal"
                android:text="@string/zero"
                android:textSize="60sp"
                android:textStyle="bold" />

This edittext have to be in one line so I put a parameter : android:singleLine="true" but when a text is too long I want to change a textSize how I can do this ?

Harin Kaklotar
  • 305
  • 7
  • 22
Kala
  • 61
  • 8

2 Answers2

0

Use editText.setTextSize(...)

Parameter will be a float value size and the text size of editText will be set to size sp

If you want a different measurement unit other than sp, use a predefined integer value unit before the size parameter. What are those predefined values you ask..?

  • COMPLEX_UNIT_DIP : Device Independent Pixels (DP)
  • COMPLEX_UNIT_IN : Inches
  • COMPLEX_UNIT_MM : Millimetres
  • COMPLEX_UNIT_PT : Points
  • COMPLEX_UNIT_PX : Raw Pixels
  • COMPLEX_UNIT_SP : Scaled Pixels

For example, if you need the text size to be 20px, use

editText.setTextSize(COMPLEX_UNIT_PX, 20.0)

Hope this helps..!

Sagar
  • 404
  • 3
  • 14
0

Android introduces the auto text size increase option

 <?xml version="1.0" encoding="utf-8"?>
  <TextView
      android:layout_width="match_parent"
      android:layout_height="200dp"
      android:autoSizeTextType="uniform"
      android:autoSizePresetSizes="@array/autosize_text_sizes" />


    <resources>
      <array name="autosize_text_sizes">
        <item>10sp</item>
        <item>12sp</item>
        <item>20sp</item>
        <item>40sp</item>
        <item>100sp</item>
      </array>
    </resources>

    I Hope this will work!
Aravind V
  • 358
  • 2
  • 10