2

enter image description hereI want to set hint * in edittext in red color as a required field. Please give me suggestion

I want this star only in red color other as it is

4 Answers4

6

Store a string in strings file like this (if you want to make email required):

<string name="email">Email<font fgcolor="red">*</font></string>

and in your editText set hint like this:

android:hint="@string/email"
AwaisMajeed
  • 2,254
  • 2
  • 10
  • 25
6

1. Add below string in your strings.xml for hints.

<string name="hints"><![CDATA[Member ID(Don\'t include dash or space)<font color=\'#cc0029\'>*</font>]]></string>

2. Programmatically set this string as hint text from your Activity class.

EditText editText = (EditText) findViewById(R.id.edit_member_id);
editText.setHint(Html.fromHtml(getString(R.string.hints)));

3. Here is your EditText in XML:

<EditText
    android:id="@+id/edit_member_id"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

OUTPUT:

enter image description here

Hope this will help~

Ferdous Ahamed
  • 21,438
  • 5
  • 52
  • 61
0

You can simply do like below one

 <android.support.design.widget.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:hint="Add text here (demo text)*"
            android:textColorHint="@android:color/holo_red_dark"
           />
Nikhil Sharma
  • 593
  • 7
  • 23
0

Add this hint in xml code like this android:hint="Put your hint text"

ITSGuru
  • 194
  • 8