Set EditText to Font Size

I am wondering how to adjust the height of the edit text to the font size. I mean that editText is always the same height, regardless of whether I change fontSize to 5 s or leave it by default. Of course, I could use something like this:

<EditText android:id="@+id/msgInput" android:layout_width="wrap_content" android:layout_height="20dp" android:inputType="textMultiLine" android:textSize="14sp" android:hint="@string/hintMsgInput"> </EditText> 

but I also want to stretch if there is more than one line. How can i do this?

[EDIT]:

Ok, I solved it as follows:

 msgInput = (EditText) findViewById(R.id.msgInput); msgInput.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) { if (msgInput.getLineCount() > 1) { msgInput.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT)); } else { int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 40, getResources().getDisplayMetrics()); msgInput.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, height)); } } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { } }); 
+5
source share
7 answers

set edit text height as wrap_content

 android:layout_height="wrap_content" 
+3
source

check it

 <EditText android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/editText1" android:textSize="5sp" android:inputType="textMultiLine" android:text="hello hru hello hru hello hru hello hru hello hru " ></EditText> 
+3
source

You provide a 20 dp limit on the height of the EditText. Do you want the textView to adjust the height in relation to the use of text size

 android:layout_height="wrap_content" 

Also, by default, a single line is false. Which guarantees a true plural string.

+2
source

If you want to make an EditText more than one line high, you can put in your EditText:

android: layout_height = "fill_parent" and set android: layout_weight = "1" to get more space to add more views to the action

0
source

you can use scrollView and add your editText to ScrollView and use this:

 android:inputType="textImeMultiLine" 
0
source

You can add the page name @style

 <style name="value_big" parent="@android:style/TextAppearance.Medium"> <item name="android:textSize">35sp</item> <item name="android:textColor">@color/white</item> <item name="android:textStyle">bold</item> <item name="android:typeface">sans</item> <item name="android:scrollbarAlwaysDrawVerticalTrack">true</item> </style> 

call it inside your edit text

  <EditText android:id="@+id/msgtext" android:layout_width="fill_parent" style="@style/value_big" android:layout_alignParentLeft="true" android:layout_marginLeft="10dip" android:layout_marginTop="10dip" android:layout_marginRight="10dip" android:inputType="textMultiLine" android:layout_height="150dip" android:gravity="top" android:padding="5dip"> </EditText> 
0
source

set android: focusable = "false" in editText

-one
source

Source: https://habr.com/ru/post/1395901/


All Articles