Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use red * symbol on top of textview in android [closed]

I have a text view. Text view is mandatory so I want * symbol on top of text view in red color.enter image description here

like image 287
android_jain Avatar asked Oct 29 '25 17:10

android_jain


2 Answers

TextView text = (TextView)findViewById(R.id.text);
String simple = "Enter your name ";
String colored = "*";
SpannableStringBuilder builder = new SpannableStringBuilder(simple+colored);

builder.setSpan(new ForegroundColorSpan(Color.RED), simple.lenth(), builder.length(), 
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

text.setText(builder);
like image 68
Divyansh Ingle Avatar answered Oct 31 '25 07:10

Divyansh Ingle


One of the easiest way to achieve this by using following code in your strings.xml file and provide color in your color.xml file

<string name="user_name">UserName <font color='red'>*</font></string>
like image 29
Harshil Rastogi Avatar answered Oct 31 '25 07:10

Harshil Rastogi