programmatically set edit text hint in android?

后端 未结 8 1408
再見小時候
再見小時候 2020-12-09 14:39

is there a way to set the text hint displayed inside of an android edittext with java? I would like for my app to be able to display different things in the edittext at diff

相关标签:
8条回答
  • 2020-12-09 15:03

    If you are using simple Editext without TextInputLayout :

    EditText etUsername;
    etUsername = (EditText) findViewById(R.id.etUsername);
    etUsername.setHint("Your Hint");
    

    If you are using Editext within TextInputLayout then you need to change property of TextInputLayout not Edittext:

    TextInputLayout layoutUser;
    layoutUser = (TextInputLayout) findViewById(R.id.inputLayoutUname);
    layoutUser.setHint(getResources().getString(R.string.hintFaculty));
    
    0 讨论(0)
  • 2020-12-09 15:07

    for editText.hint you must delete name of your edit.Text from activity_main.xml then set in the MainActivity in java or activity_main.xml because text is preferred to hint.

    0 讨论(0)
  • 2020-12-09 15:09

    Did you try the setHint?

    myTextView.setHint("My conditional hint");
    

    Hope it helps..

    0 讨论(0)
  • 2020-12-09 15:12
    ((TextView) findViewById(R.id.yourEditTextId)).setHint("hint text");
    
    0 讨论(0)
  • 2020-12-09 15:16

    Call setHint() on the EditText.

    0 讨论(0)
  • 2020-12-09 15:16

    You can try following,

    in Java

    yourEditText.setHint("hint");
    

    in Kotlin

    yourEditText.hint = "Your hint"
    
    0 讨论(0)
提交回复
热议问题