EditText一些属性
来源:互联网 发布:畅捷通软件好用吗 编辑:程序博客网 时间:2024/05/16 06:13
EditText一些属性
1.去掉下边框:android:background=”@null”
2.改变光标的颜色:android:textCursorDrawable=”@null”(光标颜色和字体颜色一致)可以在shap文件自定义光标颜色,例如:(<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<size android:width="2dp" />
<solid android:color="#ce1717" />
</shape>)定义一个深红色色光标
2.始终将光标定位到最后一行:editText.setSelection(int index)
3.将输入框内容从左上角开始:android:gravity=”left|top”
editText文字内容监听,将字数控制在200字以内
private static final int TEXT_TOTAL = 200;//文字总数 editText.addTextChangedListener(this);//添加监听,并实现以下三个方法 /** * This method is called to notify you that, within <code>s</code>, * the <code>count</code> characters beginning at <code>start</code> * are about to be replaced by new text with length <code>after</code>. * It is an error to attempt to make changes to <code>s</code> from * this callback. * * @param s * @param start * @param count * @param after */ @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} /** * This method is called to notify you that, within <code>s</code>, * the <code>count</code> characters beginning at <code>start</code> * have just replaced old text that had length <code>before</code>. * It is an error to attempt to make changes to <code>s</code> from * this callback. * * @param s * @param start * @param before * @param count */ @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (s.length() > TEXT_TOTAL){ Toast.makeText(mContext, "最多输入"+TEXT_TOTAL+"个字", Toast.LENGTH_SHORT).show(); //当字数超过设定的字数时,截取前TEXT_TOTAL个字 editText.setText(s.subSequence(0, TEXT_TOTAL)); }else { //tv_length是显示当前输入的字数,格式为: 100/200 tv_length.setText(s.length() + "/"+TEXT_TOTAL); } } /** * This method is called to notify you that, somewhere within * <code>s</code>, the text has been changed. * It is legitimate to make further changes to <code>s</code> from * this callback, but be careful not to get yourself into an infinite * loop, because any changes you make will cause this method to be * called again recursively. * (You are not told where the change took place because other * afterTextChanged() methods may already have made other changes * and invalidated the offsets. But if you need to know here, * to mark your place and then look up from here where the span * ended up. * * @param s */ @Override public void afterTextChanged(Editable s) { if (s.length() > TEXT_TOTAL){ editText.setSelection(TEXT_TOTAL); }else{ editText.setSelection(s.length()); } }
0 0
- EditText的一些属性
- EditText的一些属性
- EditText的一些属性
- EditText一些属性
- EditText的一些属性
- EditText 的一些属性设置
- EditText的一些属性设置
- Android EditText 一些属性设置
- textView 和 edittext 的一些属性
- EditText的属性InputType的一些经验
- 有关Android中EditText的一些属性
- EditText属性和一些小技巧
- EditText中一些属性的用法
- EditText属性及一些常用用法
- EditText属性
- EditText属性
- EditText属性
- EditText属性
- Android开发之Fragment的使用
- 几个常用的Swift Extension:防止按钮重复点击、增加友盟页面统计、Dispatch_once Swift实现
- word2vec
- python安装pycrypto 模块提'configure:2724: error: C compiler cannot create executables'
- iOS之Sqlite3封装
- EditText一些属性
- 栈-匹配
- 服务端测试之接口测试工具——postman
- swoole学习笔记(二)创建web服务器
- Android获取经纬度
- 栈-运算后缀表达式
- 根据 URL 请求页面过程
- windows10和ubuntu16.04时间不同步问题解决方案
- 1113. Integer Set Partition (25) PAT 甲级