我想要在EditText里面添加一个图片按钮,但是不知道怎么做,我想实现的效果如下图:
多谢指教~
不实现点击:
android:drawableRight="@drawable/icon"
实现点击的代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Enter search key" />
<ImageButton
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:src="@drawable/search"
android:layout_centerVertical="true"
android:layout_margin="5dp"
android:text="Button"/>
</RelativeLayout>
实现点击的:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<EditText
android:id="@+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true" >
</EditText>
<ImageView
android:id="@+id/imageView1"
android:padding="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/editText1"
android:layout_alignBottom="@+id/editText1"
android:layout_alignRight="@+id/editText1"
android:src="@drawable/ic_launcher" />
</RelativeLayout>
弄清楚布局就好了,
这种情况用RelativeLayout布局比较容易实现
指定好位置,EditText在底部,ImageView(或其他图片控件)在EditText的上面,且和EditText右对齐,
相应的属性都有,设置一下就好了。
这个最好使用布局文件的根节点背景图片进行伪装,同时也要做好EditText和Button的背景图片进行配合