怎么设置输入的EditText字母自动大写
1个回答
展开全部
public class MainActivity extends Activity {
EditText et ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et = (EditText) this.findViewById(R.id.editText1);
et.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
et.removeTextChangedListener(this);
final String s1 = et.getText().toString();
//判断如果是小写的字母的换,就转换
if((s1.charAt(0))-0 >= 97 && (s1.charAt(0))-0 <=122){
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
//小写转大写
et.setText(s1.toUpperCase());
}
}, 300);
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
});
}
}
EditText et ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et = (EditText) this.findViewById(R.id.editText1);
et.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
et.removeTextChangedListener(this);
final String s1 = et.getText().toString();
//判断如果是小写的字母的换,就转换
if((s1.charAt(0))-0 >= 97 && (s1.charAt(0))-0 <=122){
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
//小写转大写
et.setText(s1.toUpperCase());
}
}, 300);
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
});
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询