android显示表格边框中为什么不显示EditText边框

阅读(15210)
在安卓中我们使用默认的Editview是只能输入文字的,但是想要删除,我们得利用输入法的删除按钮来一个个删除,现在在好多应用当中,会在输入框的最后出现一个删除图片,点击就清空了所有的数据,这个很方便。下面我们来实现一下。
先看下效果图:
我们这里实现的是,当输入框有文本是,才会出现这个删除图标。当输入为空是,就会消失,其实就是自定义一个Ediiview:
* 输入文本框 右边有自带的删除按钮 当有输入时,显示删除按钮,当无输入时,不显示删除按钮。
public class ClearEditText extends EditText implements OnFocusChangeListener, TextWatcher {
* 删除按钮的引用
private Drawable mClearD
* 控件是否有焦点
private boolean hasF
public ClearEditText(Context context) {
this(context, null);
public ClearEditText(Context context, AttributeSet attrs) {
// 这里构造方法也很重要,不加这个很多属性不能再XML里面定义
this(context, attrs, android.R.attr.editTextStyle);
public ClearEditText(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
private void init() {
// 获取EditText的DrawableRight,假如没有设置我们就使用默认的图片
mClearDrawable = getCompoundDrawables()[2];
if (mClearDrawable == null) {
// throw new
// NullPointerException(&You can add drawableRight attribute in XML&);
mClearDrawable = getResources().getDrawable(R.drawable.button_login_delete);
mClearDrawable.setBounds(0, 0, mClearDrawable.getIntrinsicWidth(), mClearDrawable.getIntrinsicHeight());
// 默认设置隐藏图标
setClearIconVisible(false);
// 设置焦点改变的监听
setOnFocusChangeListener(this);
// 设置输入框里面内容发生改变的监听
addTextChangedListener(this);
* 因为我们不能直接给EditText设置点击事件,所以我们用记住我们按下的位置来模拟点击事件 当我们按下的位置 在 EditText的宽度 -
* 图标到控件右边的间距 - 图标的宽度 和 EditText的宽度 - 图标到控件右边的间距之间我们就算点击了图标,竖直方向就没有考虑
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
if (getCompoundDrawables()[2] != null) {
boolean touchable = event.getX() & (getWidth() - getTotalPaddingRight()) && (event.getX() & ((getWidth() - getPaddingRight())));
if (touchable) {
this.setText(&&);
return super.onTouchEvent(event);
* 当ClearEditText焦点发生变化的时候,判断里面字符串长度设置清除图标的显示与隐藏
public void onFocusChange(View v, boolean hasFocus) {
this.hasFoucs = hasF
if (hasFocus) {
setClearIconVisible(getText().length() & 0);
setClearIconVisible(false);
* 设置清除图标的显示与隐藏,调用setCompoundDrawables为EditText绘制上去
* @param visible
protected void setClearIconVisible(boolean visible) {
Drawable right = visible ? mClearDrawable :
setCompoundDrawables(getCompoundDrawables()[0], getCompoundDrawables()[1], right, getCompoundDrawables()[3]);
* 当输入框里面内容发生变化的时候回调的方法
public void onTextChanged(CharSequence s, int start, int count, int after) {
if (hasFoucs) {
setClearIconVisible(s.length() & 0);
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
public void afterTextChanged(Editable s) {
我们在使用的时候,只要替换Editview,换成我们自定义的就行了:
&com.test.view.ClearEditText
android:id=&@+id/edit_user&
android:layout_width=&1px&
android:layout_height=&fill_parent&
android:layout_marginLeft=&10.0dip&
android:layout_marginRight=&15.0dip&
android:layout_weight=&3&
android:background=&@android:color/white&
android:hint=&账号/邮箱/手机号码&
android:inputType=&textPersonName&
android:maxLength=&30&
android:paddingLeft=&10.0dip&
android:singleLine=&true&
android:textSize=&16.0sp& /&
这样就会有我们想要的效果了。完整demo我就不提供了。
阅读排行榜问:关于android中Manifest.xml中声明的问题一个关于WIFI开发的问题,以下码已通过编译,但编译后模拟器提示关闭,我...答:还没做过wifi。看不出来,你看看日志,里面有出错原因的描述。
问:androidEditText清除文本文本问题如何在EditText添加清除...答:FrameLayout里面放EditText,ImageView,ImageView属性android:layout_gr ty="right"EditText设置这个setOnFocusChangeListener,根据EditText是否...
问:core 快捷键?请高手指点,core 快捷键有哪些?谢谢!答:主界面显示窗口(N gator )N运行 Visual Basic应用程序的器Alt+F11保存当前的图形Ctrl+S打开文本对话框Ctrl+...
问:android里,将复选框中勾选的内容添加到一个edittext中,去掉...答:你给复选框设置,当选中的时候,就给edittext.setText如:checkbox.setOnCheckedChangeListener(new poundButton.OnCheckedChangeListener(){#...
问:请帮忙分析A/B/C分别类型和所需翻译软件,翻译急用,...第一种:SAMPLE A)&/GX&&GX ID=Beetle&&BR&Thank you for choosing...答:1.HTML网络浏览器(IE,FireFox,Opera=)2.没见过3.VB Microsoft VB6.
问:android开发:EditText中 入的相册图片如何保存在数据库里,...我保存完查看,文字能正常显示,图片的话就显示:[local]图片名字[/local]答:保存一个url是个不错的方法,然后加载的时候就可以根据路径去生成一个bitmap对象,再把这个对象显示到组件上。如果知道路径,那么显示时调用BitmapFactory....
问:core 快捷键?请高手指点,core 快捷键有哪些?谢谢!答:主界面显示窗口(N gator )N运行 Visual Basic应用程序的器Alt+F11保存当前的图形Ctrl+S打开文本对话框Ctrl+...
问:android开发中,editText怎么添加图片,如图。那个放大镜怎么...答:editText中有个属性android: ableRight=“”,可以在文本框右边加入图片,相应的android: ableLeft=“”,就是在文本框左边加入图片
问:android中.怎么点击button响应到edit text?如题,android中.怎么点击button响应到edit text?答:如果button的数字是,在他的setOnClick里设置edittext.setText("")即可。希望能帮助你。
问:怎样通过点击按钮把EditText中的内容添加到数据库Sqlite中_...答:获取不就行了
问:delphi TreeView添加子项目如题说个例子,有项目和子项目要用码实现答:这是我以前收集的一些,你看看是否有用。TreeView的使用方法:基本:TreeView是一个显示树型结构的控件,每一个节点都是一个新类,使用具有性每个...
问:请教达人,Android添加 图片后,EditText中输入的文字变淡...答:这个是图片的问题,当两者的亮度冲突会导致这样子的。
08-1607-2908-0209-15
10-1102-1504-0403-24
◇本站云标签3266人阅读
android(115)
android 开发必知的50个诀窍(51)
在实际开发中,会遇到一个布局包含一个edittext,然后这个edittext需要设置成没有边框,没有背景的效果,下面直接上代码
&span style=&white-space:pre&&
&/span&&EditText
android:layout_width=&fill_parent&
android:layout_height=&wrap_content&
android:textCursorDrawable=&@null&
android:background=&@null& /&
最后两个参数就是设置成没有边框没有背景的输入框了. 并且在这里还有一个需要注意的地方那就是,当我们把它的背景设置成null的时候这个edittext也就没有边框了已经,
android:textCursorDrawable=&@null&这个是设置我们点击输入的光标的颜色,如果像我们现在这么设置的话光标的颜色就和我们输入框中字体的颜色是一样的了,以上就是要保存的了
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:144507次
积分:2503
积分:2503
排名:第14638名
原创:116篇
转载:14篇
评论:69条
(2)(2)(1)(10)(3)(2)(3)(10)(5)(4)(6)(1)(8)(14)(5)(8)(7)(13)(18)(7)(1)android EditText 默认情况下不获取焦点(不弹出输入框)
来源:博客园
可以在EditText前面放置一个看不到的LinearLayout,让它率先获取焦点:
&LinearLayout
android:focusable="true" 
android:focusableInTouchMode="true"
android:layout_width="0px" 
android:layout_height="0px"/&

或者,让EditText之前的控件先获得焦点,都行。
免责声明:本站部分内容、图片、文字、视频等来自于互联网,仅供大家学习与交流。相关内容如涉嫌侵犯您的知识产权或其他合法权益,请向本站发送有效通知,我们会及时处理。反馈邮箱&&&&。
学生服务号
在线咨询,奖学金返现,名师点评,等你来互动Android AlertDialog有EditText无法弹出输入法的解决 - 21jhf - ITeye博客
博客分类:
如果AlertDialog中有编辑录入框(newMainLayout里面动态创建了EditText控件),show后无法显示输入法
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(modalWindowTitle);
builder.setView(newMainLayout);
builder.setNegativeButton("返回", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.dismiss();
AlertDialog ad = builder.create();
ad.show();
//下面两行代码加入后即可弹出输入法
ad.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
ad.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
浏览: 77721 次
有用,我之前也是一直遇到这个问题,查了很多资料都没有解决;最后 ...
我按楼主的方式做了
但是 为什么当我连接的时候 不输入用户名 ...
终于找到你了太好了我的mongodb就是3.0.3

我要回帖

更多关于 android显示表格边框 的文章

 

随机推荐