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) { } });
source share