代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
Java
】
自带clear图标效果的搜索栏
作者:
IamFive
/ 发布于
2012/7/23
/
683
自带clear图标效果的搜索栏
<div>/** * @(#)SearchTextView.java 2012-7-10 * Copyright 2000-2012 by iampurse@vip.qq.com. All rights reserved. */ package studio.five.common.component; import android.content.Context; import android.graphics.drawable.Drawable; import android.text.Editable; import android.text.InputType; import android.text.TextUtils; import android.text.TextWatcher; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.View; import android.widget.AutoCompleteTextView; /** * @author jlcoa * @date 2012-7-10 * @version $Revision$ */ public class SearchTextView extends AutoCompleteTextView { private Drawable[] compoundDrawables; private Drawable clearDrawable; private int clearDrawableWidth; /** * @param context * @param attrs */ public SearchTextView(Context context, AttributeSet attrs) { super(context, attrs); compoundDrawables = this.getCompoundDrawables(); clearDrawable = compoundDrawables[2]; clearDrawableWidth = clearDrawable.getBounds().width() + this.getPaddingRight() + this.getCompoundDrawablePadding(); this.displayClearDrawable(false); this.addTextChangedListener(new DisplayClearDrawableListener(this)); this.setOnTouchListener(new ClickClearDrawableListener(this)); } private void displayClearDrawable(boolean show) { this.setCompoundDrawablesWithIntrinsicBounds(compoundDrawables[0], compoundDrawables[1], show ? compoundDrawables[2] : null, compoundDrawables[3]); } public static class DisplayClearDrawableListener implements TextWatcher { private final SearchTextView txt; DisplayClearDrawableListener(final SearchTextView txt) { this.txt = txt; } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // TODO Auto-generated method stub } @Override public void afterTextChanged(Editable s) { if (txt.getText().length() > 0) { txt.displayClearDrawable(true); } else { txt.displayClearDrawable(false); } } } public static class ClickClearDrawableListener implements OnTouchListener { private final SearchTextView txt; ClickClearDrawableListener(final SearchTextView txt) { this.txt = txt; } @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_UP: int curX = (int) event.getX(); if (curX > v.getWidth() - txt.clearDrawableWidth && !TextUtils.isEmpty(txt.getText())) { txt.setText(""); int cacheInputType = txt.getInputType();// backup the input type txt.setInputType(InputType.TYPE_NULL);// disable soft input txt.onTouchEvent(event);// call native handler txt.setInputType(cacheInputType);// restore input type // InputMethodManager imm = (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); // txt.requestFocus(); // imm.showSoftInput(txt, 0); return false; // let txt focus still } break; } return false; } } }
试试其它关键字
搜索栏
同语言下
.
List 切割成几份 工具类
.
一行一行读取txt的内容
.
Java PDF转换成图片并输出给前台展示
.
java 多线程框架
.
double类型如果小数点后为零则显示整数否则保留两位小
.
将图片转换为Base64字符串公共类抽取
.
sqlParser 处理SQL(增删改查) 替换schema 用于多租户
.
JAVA 月份中的第几周处理 1-7属于第一周 依次类推 29-
.
java计算两个经纬度之间的距离
.
输入时间参数计算年龄
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
IamFive
贡献的其它代码
(
2
)
.
回溯法解八皇后问题
.
自带clear图标效果的搜索栏
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3