【问题标题】:How to put getLocation / compass button inside edittext field android studio如何将getLocation / compass按钮放在edittext字段android studio中
【发布时间】:2016-01-17 11:02:16
【问题描述】:

我想将 getlocation / compass 按钮放在我的编辑字段中,我不太确定如何执行此操作或从哪里开始,请有人指导我。我要做的是,类似于下面的两个屏幕截图;

我尝试过使用布局,但我似乎无法弄清楚如何做到这一点,我已经完成了基本布局;

<?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>

【问题讨论】:

    标签: android google-maps android-layout location postal-code


    【解决方案1】:

    您可以在xml中使用android:drawableRight属性:
    https://developer.android.com/reference/android/widget/TextView.html#attr_android:drawableRight

    类似的东西:

    <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"/>
    

    其中YOUR_COMPASS_DRAWABLEres/drawable/文件夹中的罗盘图片(不同的屏幕必须使用不同的图片:mdpi、hdpi等)

    【讨论】:

    猜你喜欢
    • 2012-10-20
    • 1970-01-01
    • 1970-01-01
    • 2011-04-28
    • 2018-12-23
    • 2020-01-01
    • 2022-06-12
    • 2013-06-30
    • 2011-08-10
    相关资源
    最近更新 更多