-2

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>
halfer
  • 19,824
  • 17
  • 99
  • 186
Sangeeta
  • 961
  • 2
  • 13
  • 34

3 Answers3

4

Try this, Add textColorHint attribute for your EditText

android:textColorHint="#FFFFFF"
Murali Ganesan
  • 2,925
  • 4
  • 20
  • 31
  • thanks.. i set the color.. and it works.. but #FFFFFF (suggested by you) is white color.. so it too doesnt show.. i used blue color and now it is showing.. thanks.. :) – Sangeeta Dec 10 '14 at 09:48
  • it needs 15 reputation.. so i cant. :( – Sangeeta Dec 10 '14 at 10:11
  • 1
    If you wanna to set programmatic use this code snippet edit_text.setHintTextColor(getResources().getColor(R.color.blue_color)); – Murali Ganesan Dec 10 '14 at 10:12
0

There might be problem in your string.xml. Did you define hint_domain properly in strings.xml. Can you please show your strings.xml file?

Aashish Gulabani
  • 141
  • 6
  • 24
0

Try changing

android:inputType="text"

with android:singleLine="true"

or do

android:gravity="right" or android:gravity="left"

once using android:ellipsize="end" fixed it for me Weird bug.

You can use

android:ellipsize="end"

android:maxLines="1"

to show your hint text in single line but you wont be able to see the whole text because android:ellipsize="end" truncates the text at the end.

  • it(hint text) was taking white color by default. i set the color and it works.. thanks for the concern. :) – Sangeeta Dec 10 '14 at 09:51