Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android EditText draw a divider line between its drawable and its text

I have an EditText with a drawableLeft image. I need to add a vertical line in EditText right beside my drawableLeft like this example:

enter image description here

Easiest way that I can think of is to add that line into my drawable image. But generally is there any other way to do this?

like image 355
abeikverdi Avatar asked Dec 31 '15 05:12

abeikverdi


2 Answers

  1. Create a rectangular rounded corner shape in res/drawable/shape.xml

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
    <stroke android:width="3dip" android:color="@android:color/darker_gray" />
    <corners android:radius="10dip"/>
    <padding android:left="10dip" android:top="10dip" android:right="10dip"        android:bottom="10dip" />
    </shape>
    
  2. Now create a layout

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/shape"
    android:gravity="center_vertical">
    
    
    <ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageView"
    android:src="@drawable/ic_launcher"/>
    
    <View
    android:layout_width="2dp"
    android:layout_height="match_parent"
    android:background="@android:color/darker_gray"
    android:layout_marginLeft="10dp"/>
    
    <EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/editText"
    android:layout_weight="1"
    android:background="@null"
    android:layout_marginLeft="10dp"
    android:hint="Your bitcoin address here"/>
    
    
    </LinearLayout>
    
  3. I have set the Linear layout background with th rectangular rounded corner shape. It looks exactly as the image preview of urs.

like image 87
kevz Avatar answered Oct 19 '22 19:10

kevz


You can create a layout and attache to the editText as a property

android:drawableRight="@android:drawable/your_layout"

for example

<EditText 
   android:width="match_parent"
   android:drawableLeft="@android:drawable/your_layout"
/>

in your your_layout.xml file you can put anything you want.

Please check this

like image 39
Zumry Mohamed Avatar answered Oct 19 '22 17:10

Zumry Mohamed