0

I want to put the getlocation / compass button inside my editfield, I am not quite sure how I can do this or where to start, please can someone guide me. What I have to do is, something like the two screenshots below;

enter image description here

I have tried playing around with the layout but I can't seem to figure out how I can do this, I have the basic layout done;

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:background="?attr/colorPrimary"
    android:orientation="vertical" >


    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="100dp">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textPostalAddress"
        android:ems="10"
        android:hint="Your Post Code"
        android:id="@+id/editText"
        android:layout_gravity="center_horizontal"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"/>

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Proceed"
        android:background="#fff"
        android:id="@+id/button"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp" />
    </LinearLayout>
</LinearLayout>
Henry
  • 1,042
  • 2
  • 17
  • 47

1 Answers1

0

You can use android:drawableRight attribute in xml:
https://developer.android.com/reference/android/widget/TextView.html#attr_android:drawableRight

Something like that:

<EditText 
android:layout_width="match_parent" 
android:layout_height="wrap_content"
android:inputType="textPostalAddress" 
android:ems="10" 
android:hint="Your Post Code" 
android:id="@+id/editText"
android:drawableRight="@drawable/YOUR_COMPASS_DRAWABLE"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="10dp" 
android:layout_marginRight="10dp"/>

where YOUR_COMPASS_DRAWABLE is a compass picture in res/drawable/ folder (you must used different pictures for different screen: mdpi, hdpi, etc.)

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
nick_kryloff
  • 126
  • 6
  • Please can you give me an example? I am fairly new and don't know where to start. Thanks. – Henry Jan 17 '16 at 12:03
  • Is it possible to get a onClick listener for the compass? and also, is it possible to get a X in the editfield that enables users to empty the editfield like in the Hungryhouse and justeat screenshot – Henry Jan 17 '16 at 12:19
  • This answers can help you http://stackoverflow.com/questions/20724287/how-can-i-add-onclicklistener-to-drawable-in-edittext http://stackoverflow.com/questions/3554377/handling-click-events-on-a-drawable-within-an-edittext – nick_kryloff Jan 17 '16 at 12:22