Android 设置DrawableRight和DrawableLeft 点击事件
来源:互联网 发布:郑州八度网络 编辑:程序博客网 时间:2024/05/16 06:49
<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);"></span><pre name="code" class="java">package com.ulucu.xview;import android.content.Context;import android.graphics.drawable.Drawable;import android.util.AttributeSet;import android.view.MotionEvent;import android.view.View;import android.widget.EditText;/** * Created by lbin on 2015/12/9. */public class XEditText extends EditText { private DrawableLeftListener mLeftListener ; private DrawableRightListener mRightListener ; final int DRAWABLE_LEFT = 0; final int DRAWABLE_TOP = 1; final int DRAWABLE_RIGHT = 2; final int DRAWABLE_BOTTOM = 3; public XEditText(Context context, AttributeSet attrs) { super(context, attrs); } public XEditText(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } public XEditText(Context context) { super(context); } public void setDrawableLeftListener(DrawableLeftListener listener) { this.mLeftListener = listener; } public void setDrawableRightListener(DrawableRightListener listener) { this.mRightListener = listener; } public interface DrawableLeftListener { public void onDrawableLeftClick(View view) ; } public interface DrawableRightListener { public void onDrawableRightClick(View view) ; } @Override public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_UP: if (mRightListener != null) { Drawable drawableRight = getCompoundDrawables()[DRAWABLE_RIGHT] ; if (drawableRight != null && event.getRawX() >= (getRight() - drawableRight.getBounds().width())) { mRightListener.onDrawableRightClick(this) ; return true ; } } if (mLeftListener != null) { Drawable drawableLeft = getCompoundDrawables()[DRAWABLE_LEFT] ; if (drawableLeft != null && event.getRawX() <= (getLeft() + drawableLeft.getBounds().width())) { mLeftListener.onDrawableLeftClick(this) ; return true ; } } break; } return super.onTouchEvent(event); }}
<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">然后可以写一个自定义监听类。</span>
private class DrawableRightClickListener implements XEditText.DrawableRightListener { @Override public void onDrawableRightClick(View view) { if (!mIsShow) { network_password.setCompoundDrawablesWithIntrinsicBounds(R.mipmap.icon_password, 0, R.mipmap.btn_nosee, 0) ; network_password.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD) ; } else { network_password.setCompoundDrawablesWithIntrinsicBounds(R.mipmap.icon_password, 0, R.mipmap.btn_see, 0) ; network_password.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD) ; } mIsShow = !mIsShow ; } }
0 0
- Android 设置DrawableRight和DrawableLeft 点击事件
- Android 设置DrawableRight和DrawableLeft 点击事件
- Android 设置DrawableRight和DrawableLeft点击事件
- EditText设置DrawableRight,DrawableLeft,DrawableTop... 点击事件
- Android 设置EditText的DrawableRight和DrawableLeft 的通用点击事件
- 自定义EditText 实现drawableRight/drawableLeft 点击事件
- android 动态设置drawableTop,drawableLeft,drawableRight,drawableBottom.
- TextView设置drawableLeft,drawableRight,drawableTop和drawableBottom
- android drawableRight 添加点击事件
- Android中动态设置TextView的drawableLeft和drawableRight的时候图片未出现
- Android使用代码为textview设置drawableLeft或drawableRight
- 处理DrawableRight点击事件
- 动态设置drawableTop,drawableLeft,drawableRight,drawableBottom
- 代码中设置drawableLeft以及drawableRight
- 设置drawableTop、drawableLeft、drawableRight、drawableBottom图片大小
- View代码设置drawableLeft,drawableRight,drawableTop,drawableBottom
- TextView 代码设置drawableLeft、drawableRight、drawableTop、drawableBottom
- 给EditText的drawableRight属性的图片设置点击事件
- Service
- 【Oracle】--PL/SQL导入Oracle sql脚本"傻瓜教程"
- 解决adb连接问题
- spring框架学习过程的小知识
- 对Xcode菜单选项的详细探索
- Android 设置DrawableRight和DrawableLeft 点击事件
- 如何查看linux中的MBR记录
- java 压缩和解压lzo文件
- 遍历Map的四种方法
- thinkphp 3.2 =》0623-7 调用数据库
- @NotNull和@NotEmpty和@NotBlank区别
- 友盟分享集成
- OCP-1Z0-051-2015-43题
- 常用WebService(逐渐更新)