<EditTextandroID:ID="@+ID/account_et"androID:layout_wIDth="match_parent"androID:layout_height="fill_parent"androID:layout_weight="1"androID:drawableRight="@drawable/icon_backall"androID:ems="10"androID:hint="@string/str_md_email"androID:inputType="textEmailAddress"androID:padding="10dp" ></EditText>
我想在EditText聚焦时显示drawableRight.
隐藏而没有焦点.
另一个是我想设置drawableRight的OnClickListener.
我能怎么做?
activity_main.xml<relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" xmlns:tools="http://schemas.androID.com/tools" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" > <EditText androID:ID="@+ID/editText1" androID:layout_wIDth="wrap_content" androID:layout_height="130dp" androID:layout_alignParentleft="true" androID:layout_alignParentRight="true" androID:layout_alignParenttop="true" androID:inputType="textEmailAddress" > </EditText> <ImageVIEw androID:ID="@+ID/imageVIEw1" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_alignParentRight="true" androID:layout_alignParenttop="true" androID:layout_marginRight="14dp" androID:layout_margintop="43dp" androID:src="@drawable/ic_launcher" androID:visibility="invisible" > </ImageVIEw> <EditText androID:ID="@+ID/editText2" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_alignParentleft="true" androID:layout_alignParentRight="true" androID:layout_below="@+ID/editText1" androID:ems="10" > <requestFocus /> </EditText></relativeLayout>
这是执行drawable选项的类文件
MainActivity.javapackage com.example.doubtedittext;import androID.os.Bundle;import androID.app.Activity;import androID.app.AlertDialog;import androID.content.DialogInterface;import androID.vIEw.VIEw;import androID.Widget.EditText;import androID.Widget.ImageVIEw;public class MainActivity extends Activity { private EditText etext; private ImageVIEw imageVIEw1; @OverrIDe public voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_main); etext = (EditText) findVIEwByID(R.ID.editText1); imageVIEw1 = (ImageVIEw) findVIEwByID(R.ID.imageVIEw1); etext.setonFocuschangelistener(new VIEw.OnFocuschangelistener() { @OverrIDe public voID onFocusChange(VIEw v,boolean hasFocus) { if (hasFocus) { imageVIEw1.setVisibility(VIEw.VISIBLE); } else { imageVIEw1.setVisibility(VIEw.INVISIBLE); } } }); imageVIEw1.setonClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw v) { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder( MainActivity.this); // set Title alertDialogBuilder.setTitle("Your Title"); // set dialog message alertDialogBuilder .setMessage("Click yes to exit!") .setCancelable(false) .setPositivebutton("Yes",new DialogInterface.OnClickListener() { public voID onClick(DialogInterface dialog,int ID) { // if this button is clicked,close // current activity MainActivity.this.finish(); } }) .setNegativebutton("No",just close // the dialog Box and do nothing dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); } }); }}
您需要成功执行的 *** 作…..
总结以上是内存溢出为你收集整理的android – 可编辑文本的drawableRight全部内容,希望文章能够帮你解决android – 可编辑文本的drawableRight所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)