当前位置: 移动技术网 > IT编程>开发语言>.net > android软键盘汉字的codes如何确定

android软键盘汉字的codes如何确定

2020年07月14日  | 移动技术网IT编程  | 我要评论

找了好多自定义软键盘的博客,但是都没说明白汉字是怎么转换成codes的,记录一下我的两种方法。

一、在线转换

1、输入汉字转换Unicode,例如“浙”转换成“\u6d59”。

2、https://tool.oschina.net/hexconvert/选16进制转10进制,输入上面的“6d59”,转换结果为“27993”。

<Key android:codes="27993" android:keyLabel="浙"
    android:horizontalGap="2%p" android:keyWidth="8%p" />

二、代码实现

public static String str2Unicode(String str){
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < str.length(); i++) {
        buffer.append(Integer.toHexString(str.charAt(i)));
    }
    return buffer.toString();
}

public static String sixteen2Ten(String str){
    int ten = Integer.parseInt(str,16);
    return String.valueOf(ten);
}

调用

sixteen2Ten(str2Unicode("浙"));

输出

27993

本文地址:https://blog.csdn.net/qy1993qy/article/details/107313154

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网