Hello all..
This simple example will show you how to change the hint text color in android
Here is the java code to simply do this.
youredittext.setHint(Html.fromHtml("<font color='#FF0000'>Hello</font> "));
here is a sample project to view the difference.
This is the contents of the main java file.
package com.coderzheaven.pack; import android.app.Activity; import android.os.Bundle; import android.text.Html; import android.widget.EditText; public class HintColorDemoActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); EditText ed = (EditText)findViewById(R.id.editText1); ed.setHint("Hello "); EditText ed2 = (EditText)findViewById(R.id.editText2); ed2.setHint(Html.fromHtml("<font color='#FF0000'>Hello</font> ")); } }
The main.xml file
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <EditText android:id="@+id/editText1" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" > <requestFocus /> </EditText> <EditText android:id="@+id/editText2" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" > </EditText> </LinearLayout>
Here I am setting a read color to the second edittext hint.
See the screenshot.
Please leave your comments if you found this useful.