Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a edit text with a permanent hint inside it

Tags:

android

I have a edit text in which the user enters amount. What I want to do is set a textview value before it that is not editable by the user like "INR" and then the user will enter the amount in front of it. I want edittext to look like the below one. How can I do that?

enter image description here

<EditText
        android:id="@+id/Eamnt"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/button1"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="180dp"
        android:ems="10"
        android:inputType="numberDecimal"
like image 241
Audi Avatar asked Dec 06 '22 11:12

Audi


1 Answers

Try to use RelativeLayout which contains a TextView and an EditText. I did something below, try it.

<RelativeLayout
  android:layout_width="match_parent"
  android:layout_height="50dp"
  android:background="@android:drawable/editbox_background" >

<TextView 
    android:id="@+id/constant_text"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_centerVertical="true"
    android:gravity="center_vertical|center_horizontal"
    android:textStyle="bold"
    android:textColor="#C0C0C0"
    android:text="INR"
    android:background="@android:color/transparent" />

<EditText 
    android:id="@+id/amount"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_toRightOf="@+id/constant_text"
    android:textColor="#000000"
    android:textStyle="bold"
    android:background="@android:color/transparent"
    android:paddingLeft="5dp"
    android:text="100 000" />


</RelativeLayout>
like image 182
osayilgan Avatar answered Jan 21 '23 23:01

osayilgan