本文介绍了文本转换:大写相当于Android的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是否存在?我需要一个TextView它总是大写。
Does this exist? I need to make a TextView which is always uppercase.
推荐答案
我没有看到这样的事情在TextView的属性,但是你可能只是使文字大写设置前:
I don't see anything like this in the TextView attributes, however you could just make the text uppercase before setting it:
textView.setText(text.toUpperCase());
如果TextView的是一个EditText和任何你想要的用户类型为大写,你可以实现一个TextWatcher和使用的EditText addTextChangedListener添加它,一个在onTextChange方法取得用户输入并与在同一文本替换大写。
If the TextView is an EditText and you want whatever the user types to be uppercase you could implement a TextWatcher and use the EditText addTextChangedListener to add it, an on the onTextChange method take the user input and replace it with the same text in uppercase.
editText.addTextChangedListener(upperCaseTextWatcher);
final TextWatcher upperCaseTextWatcher = new TextWatcher() {
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
editText.setText(editText.getText().toString().toUpperCase());
editText.setSelection(editText.getText().toString().length());
}
public void afterTextChanged(Editable editable) {
}
};
这篇关于文本转换:大写相当于Android的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!