I have a mandatory EditText
that has a placeholder with mandatory symbol *
that has to be red. Help with this guys.
Asked
Active
Viewed 565 times
1

Kaushik
- 6,150
- 5
- 39
- 54

Vladimir Abazarov
- 333
- 1
- 12
-
1what do you have and what did you try? – Bart Hofma Dec 05 '14 at 12:04
-
I have tried to make an adapter with two TextViews, and the one to have red color and make some ugly set visible things on click... – Vladimir Abazarov Dec 05 '14 at 12:07
-
1i meant to say, post some code. i will not do your homework if you're not willing to do any effort. but some guy did so you're lucky i guess – Bart Hofma Dec 05 '14 at 12:08
-
I am trying his answer now. Let you know here if it works. 10x Bart. – Vladimir Abazarov Dec 05 '14 at 12:10
2 Answers
6
Try like this, try this discussion for more detail.
TextView text = (TextView)findViewById(R.id.text);
String simple = "First Name ";
String colored = "*";
SpannableStringBuilder builder = new SpannableStringBuilder();
builder.append(simple);
int start = builder.length();
builder.append(colored);
int end = builder.length();
builder.setSpan(new ForegroundColorSpan(Color.RED), start, end,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
text.setHint(builder);

Community
- 1
- 1

Remees M Syde
- 2,564
- 1
- 19
- 42
-
1This is the answer, 10x Remees M Syde for the help. I will edit your answer only on one place to be perfect. text.setText(builder); becomes > text.setHint(builder); – Vladimir Abazarov Dec 05 '14 at 12:18
-
-1
Create your own custom view with its structure like
<RelativeLayout
android:layout_width="100dp"
android:layout_height="40dp">
<EditText
android:layout_width="100dp"
android:layout_height="40dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:id="@+id/placeholder_left"
android:text="First name"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_toRightOf="@+id/placeholder_left"
android:textColor="@color/red"
android:text="*"/>
Add logic to handle the visibility of the "placeholder" TextView upon text change in the EditText.

Patrick Chan
- 1,019
- 10
- 14
-
10x for the help Patrick Chan, but Remees M Syde's answer is better for me. – Vladimir Abazarov Dec 05 '14 at 12:21