寫一個類繼承ReplacementTransformationMethod
* 小寫字母自動轉化爲大寫*/
public class TransInformation extends ReplacementTransformationMethod{
/**
* 原本輸入的小寫字母
*/
@Override
protected char[] getOriginal() {
char [] small = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
return small;
}
/**
* 替代爲大寫字母
*/
@Override
protected char[] getReplacement() {
char [] big = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
return big;
}
}
爲EditText添加監聽方法setTransformationMethod
EditText et = new EditText();
et.setTransformationMethod(new TransInformation());