This topic created in 2072 days ago, the information mentioned may be changed or developed.
Supplement 1 · Sep 15, 2020
附代码
public static class AllCapTransformationMethod extends ReplacementTransformationMethod {
private char[] lower = {'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'};
private char[] upper = {'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'};
private boolean allUpper;
public AllCapTransformationMethod(boolean needUpper) {
this.allUpper = needUpper;
}
protected char[] getOriginal() {
if (allUpper) {
return lower;
} else {
return upper;
}
}
protected char[] getReplacement() {
if (allUpper) {
return upper;
} else {
return lower;
}
}
}
使用(项目中不含 needUpper 为 false 的调用):
editText.setTransformationMethod(new AllCapTransformationMethod(true));