EditText输入字母自动大写

直接上代码:

editText.setTransformationMethod(new TransInformation());

/**
 * 小写字母自动转化为大写
 */
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;
	}
}
发布了33 篇原创文章 · 获赞 20 · 访问量 8万+

猜你喜欢

转载自blog.csdn.net/huangwenkui1990/article/details/102723987