Android add placeholder text to EditText

后端 未结 8 835
感动是毒
感动是毒 2020-12-02 04:34

How can I add a placeholder text to EditText in the class that isn\'t in the XML?

I have the following EditText in my code which will be sh

相关标签:
8条回答
  • 2020-12-02 05:04

    If you want to insert text inside your EditText view that stays there after the field is selected (unlike how hint behaves), do this:

    In Java:

    // Cast Your EditText as a TextView
    ((TextView) findViewById(R.id.email)).setText("your Text")
    

    In Kotlin:

    // Cast your EditText into a TextView
    // Like this
    (findViewById(R.id.email) as TextView).text = "Your Text"
    // Or simply like this
    findViewById<TextView>(R.id.email).text = "Your Text"
    
    0 讨论(0)
  • 2020-12-02 05:11

    In Android Studio you can add Hint (Place holder) through GUI. First select EditText field on designer view. Then Click on Component Tree Left side of IDE (Normally it's there, but it may be there minimized) There you can see Properties of selected EditText. Find Hint field as below Image

    There you can add Hint(Place holder) to EditText

    0 讨论(0)
提交回复
热议问题