由网友(你陌生的让我害怕)分享简介:这是否存在?我需要一个TextView它总是大写。Does this exist? I need to make a TextView which is always uppercase.推荐答案我没有看到这样的事情在TextView的属性,但是你可能只是使文字大写设置前:I don't see anythin...
这是否存在?我需要一个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) {
}
};
相关推荐
最新文章