mEditTextView = (EditText) findViewById(R.id.account_password)
mCheckBoxView.setOnCheckedChangeListener(checkBox_Listener)
private CheckBox.OnCheckedChangeListener checkBox_Listener = new CheckBox.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
if(mCheckBoxView.isChecked()){
//文本正常显示
mEditTextView.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD)
Editable etable = mEditTextView.getText()
Selection.setSelection(etable, etable.length())
}else{
//兄闭迟文本以密码形式显示
mEditTextView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD)
//下面两行代码态带实现: 输入框光羡李标一直在输入文本后面
Editable etable = mEditTextView.getText()
Selection.setSelection(etable, etable.length())
}
}
}
希望能帮到你 帮到你了 请采纳 谢谢
布局里加上这一句:
android:inputType="textPassword"就好了。
方法1::
在布局文件中设置文本编辑框属性作字符数限制,android:maxLength="10" 即限制最大输入字符个数为10。
方法2:在代码中使用InputFilter 进行过滤
public class 敏团源MyActivity extends Activity
{
private EditText text
@Override
public void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState)
setContentView(R.layout.main)
text = (EditText)findViewById(R.id.text)
text .setFilters(new InputFilter[]{new InputFilter.LengthFilter(20)})
}
}
方法3:利用 TextWatcher 进行监听
继承TextWatcher接口,对输入进行监听
pblic class MaxLengthWatcher implements 桥态TextWatcher
{
private int maxLen = 0
private EditText editText = null
public MaxLengthWatcher(int maxLen, EditText editText) 或宽{
this.maxLen = maxLen
this.editText = editText
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
Editable editable = editText.getText()
int len = editable.length()
if(len > maxLen)
{
int selEndIndex = Selection.getSelectionEnd(editable)
String str = editable.toString()
//截取新字符串
String newStr = str.substring(0,maxLen)
editText.setText(newStr)
editable = editText.getText()
//新字符串的长度
int newLen = editable.length()
//旧光标位置超过字符串长度
if(selEndIndex > newLen)
{
selEndIndex = editable.length()
}
//设置新光标所在的位置
Selection.setSelection(editable, selEndIndex)
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
}
在activity中为EditText添加监听
public class MyActivity extends Activity {
private EditText text
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main)
text = (EditText) findViewById(R.id.entry)
//限制为10
text.addTextChangedListener(new MaxLengthWatcher(10, editText))
}
}
edit = (EditText) this.findViewById(R.id.editText1)edit.setInputType(InputType.TYPE_NULL)
edit.setTransformationMethod(PasswordTransformationMethod.getInstance())
完拆睁戚敬美旅仔岁解决
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)