Sangeeta Sangeeta -4 years ago 158
Android Question

Hint not working in EditText on Android

I am using Editbox in which I have used hints. but when I run application, hints do not show. I have tried setting hints programmatically too, but it doesn't work.

Here is my code:

<EditText
android:id="@+id/mobile_registration_txtDomain"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:hint="@string/hint_domain"
android:lines="1"
android:background="@drawable/edittxt_drwable"
android:textSize="14sp"
android:textColor="#808080" />


here is edittxt_drwable.xml code---- which is stored in drawables, used to change color of edittext when focussed and lost focus.

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_window_focused="false"
android:state_enabled="true"
android:drawable="@drawable/new_border" />

<item
android:state_window_focused="false"
android:state_enabled="false"
android:drawable="@drawable/new_border" />

<item
android:state_pressed="true"
android:drawable="@drawable/focussed_border" />

<item
android:state_enabled="true"
android:state_focused="true"
android:drawable="@drawable/focussed_border" />

<item
android:state_enabled="true"
android:drawable="@drawable/new_border" />

<item
android:state_focused="true"
android:drawable="@drawable/new_border" />

<item
android:drawable="@drawable/new_border" />

</selector>


here new_border.xml code which gives black border to edittext when it is unclicked.

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:thickness="0dp"
android:shape="rectangle">

<stroke android:width="2dp"
android:color="#808080"/>

<corners android:radius="5dp"
/>

<padding android:left="10dp"
android:top="5dp"
android:right="10dp"
android:bottom="5dp"/>

</shape>


here focussed_border.xml code-- which gives orange border to edittxt when edittext is focussed.

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:thickness="0dp"
android:shape="rectangle">

<stroke android:width="2dp"
android:color="#FF8C00"/>

<corners android:radius="5dp"
/>

<padding android:left="10dp"
android:top="5dp"
android:right="10dp"
android:bottom="5dp"/>

</shape>

Answer Source

Try this, Add textColorHint attribute for your EditText

android:textColorHint="#FFFFFF"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download