I have an EditText
.
When i have less then 8 characters, the EditText
has an minimum width.
I want to use wrap_content
.
It is caused because by the hint
.
How can i solve this? I have tried everything.
I want like this:
Here is my code
<EditText
android:id="@+id/et_actionbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="YOLO"
android:hint="New team"
android:gravity="center"
android:textColor="@color/gray1"
android:textStyle="bold"
android:background="@color/gold"
android:layout_centerInParent="true"
android:minWidth="0dp"
android:minEms="0"
android:minHeight="0dp"
android:paddingLeft="0dp"
android:layout_marginLeft="0dp"
/>
The only way to do this is to remove the hint or reduce the length of hint string. If you don't want to remove the hint, hide it when a text is entered into the EditText.
editText.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
if(!TextUtils.isEmpty(editText.getText().toString())){
editText.setHint("");
}else{
edittext.setHint(R.string.hint);
}
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With