在Android的可点击的绘制里面的EditText [英] clickable drawable inside EditText in android
本文介绍了在Android的可点击的绘制里面的EditText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个内部绘制一个EditText。我想使绘制点击,这样,当用户单击绘制我能有一个具体的行动。我怎么做?我的EditText是:
<的EditText
机器人:ID =@ + ID /手机
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_gravity =CENTER_HORIZONTAL
机器人:layout_marginBottom =5DP
机器人:drawableRight =@绘制/ question_mark
机器人:提示=电话号码
机器人:imeActionId =@ + ID / PHONE_NUM
机器人:MAXLINES =1
机器人:单线=真
机器人:文字颜色=#000000/>
解决方案
由于吉娜上面的建议,您可以通过使用替代drawableRight财产RelativeLayout的实现这一目标。低于code放的ImageView您的EditText
的右部 < RelativeLayout的
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT><的EditText
机器人:ID =@ + ID /手机
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_gravity =CENTER_HORIZONTAL
机器人:layout_marginBottom =5DP
机器人:提示=电话号码
机器人:imeActionId =@ + ID / PHONE_NUM
机器人:MAXLINES =1
机器人:单线=真
机器人:文字颜色=#000000/> < ImageView的
机器人:ID =@ + ID / imageView1
机器人:layout_width =30dp
机器人:layout_height =30dp
机器人:layout_alignRight =@ + ID /手机
机器人:layout_marginRight =10dp
机器人:layout_centerVertical =真
机器人:SRC =@绘制/ ic_launcher/>< / RelativeLayout的>
I have an EditText with a drawable inside. I want to make the drawable clickable so that I can have a specific action when user clicks the drawable. How do I do that? My EditText is:
<EditText
android:id="@+id/phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="5dp"
android:drawableRight="@drawable/question_mark"
android:hint="phone number"
android:imeActionId="@+id/phone_num"
android:maxLines="1"
android:singleLine="true"
android:textColor="#000000" />
解决方案
As Gina suggested above, you can achieve this by using RelativeLayout instead of drawableRight property. Code below puts the imageview to the right part of your EditText
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="@+id/phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="5dp"
android:hint="phone number"
android:imeActionId="@+id/phone_num"
android:maxLines="1"
android:singleLine="true"
android:textColor="#000000" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignRight="@+id/phone"
android:layout_marginRight="10dp"
android:layout_centerVertical="true"
android:src="@drawable/ic_launcher" />
</RelativeLayout>
这篇关于在Android的可点击的绘制里面的EditText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文