当前位置: 代码迷 >> Android >> Android EditText 让编辑框唯其如此输入中文汉字
  详细解决方案

Android EditText 让编辑框唯其如此输入中文汉字

热度:211   发布时间:2016-04-28 04:42:13.0
Android EditText 让编辑框只能输入中文汉字

/**

* 判定输入汉字

*?

* @param c

* @return

*/

public boolean isChinese(char c) {

Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);

if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS || ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A || ub == Character.UnicodeBlock.GENERAL_PUNCTUATION || ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION || ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) {

return true;

}

return false;

}

?

/**

* 检测String是否全是中文

*?

* @param name

* @return

*/

public boolean checkNameChese(String name) {

boolean res = true;

char[] cTemp = name.toCharArray();

for (int i = 0; i < name.length(); i++) {

if (!isChinese(cTemp[i])) {

res = false;

break;

}

}

return res;

}

  相关解决方案