How to get a red asterisk in a entry

前端 未结 4 977
情书的邮戳
情书的邮戳 2020-12-31 10:56

How do you get a red asterisk in a entry so that you can display it at the end of the text to indicate its a required field, like: Enter your name * (asterisk will be red).

4条回答
  •  隐瞒了意图╮
    2020-12-31 11:12

    Refer to this for examples on how to style portions of a textview. Here's how you could do it for a red asterisk.

    EditText editTxt = new EditText(this);
    editTxt.setText("Testing asterisk *");
    Spannable str = editTxt.getTxt();
    int loc = editTxt.getTxt().toString().indexOf("*");
    str.setSpan(new ForegroundColorSpan(Color.RED), loc, 1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
    

提交回复
热议问题