programmatically set edit text hint in android?

﹥>﹥吖頭↗ 提交于 2019-11-28 10:40:00

Did you try the setHint?

myTextView.setHint("My conditional hint");

Hope it helps..

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));

Call setHint() on the EditText.

((TextView) findViewById(R.id.yourEditTextId)).setHint("hint text");

if you are using actionbarsherlock searchview, this is the best way to set string dynamically

   AutoCompleteTextView searchTextView =
                    (AutoCompleteTextView) mSearchView.findViewById(R.id.abs__search_src_text);

searchTextView.setHint(getResources().getString(R.string.search));

Kotlin

editText.hint = "Your hint"

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.

You can try following,

in Java

yourEditText.setHint("hint");

in Kotlin

yourEditText.hint = "Your hint"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!