相关文章推荐
逆袭的黑框眼镜  ·  Sql ...·  1 年前    · 
风流的书签  ·  jestjs - What is the ...·  1 年前    · 
追风的茶壶  ·  process.send is ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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
                Thanks! This worked good for me! I can't vote up your question. I need 2 reputation. If you vote my question, i can vote your answer :)
– BertLeonaers
                Apr 25, 2014 at 11:18

I guess it's not possible to change the font of hint as font is same for hint and text

but the work around will be

First set the text size

 android:textSize="20sp"

second

then on text change listener change the text size programitically to 10sp. then u might be able to use wrap content...

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.