早上好, 我在Android上创建自定义键盘,我希望当用户点击大写按钮查看大写字母中的所有字母时,当用户关闭大写字母以将字母返回小(在xml中)并且如果我可以更改大写字母按钮背景何时启用。
这是字母的xml代码:
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
android:keyWidth="10%p"
android:horizontalGap="0px"
android:verticalGap="0px"
android:keyHeight="60dp"
>
<Row>
<Key android:codes="113" android:keyLabel="q" android:keyEdgeFlags="left"/>
<Key android:codes="119" android:keyLabel="w"/>
<Key android:codes="101" android:keyLabel="e"/>
<Key android:codes="114" android:keyLabel="r"/>
<Key android:codes="116" android:keyLabel="t"/>
<Key android:codes="121" android:keyLabel="y"/>
<Key android:codes="117" android:keyLabel="u"/>
<Key android:codes="105" android:keyLabel="i"/>
<Key android:codes="111" android:keyLabel="o"/>
<Key android:codes="112" android:keyLabel="p" android:keyEdgeFlags="right"/>
</Row>
<Row>
<Key android:codes="-500" android:keyLabel="" android:keyWidth="5%p" android:keyEdgeFlags="left"/>
<Key android:codes="97" android:keyLabel="a"/>
<Key android:codes="115" android:keyLabel="s"/>
<Key android:codes="100" android:keyLabel="d"/>
<Key android:codes="102" android:keyLabel="f"/>
<Key android:codes="103" android:keyLabel="g"/>
<Key android:codes="104" android:keyLabel="h"/>
<Key android:codes="106" android:keyLabel="j"/>
<Key android:codes="107" android:keyLabel="k"/>
<Key android:codes="108" android:keyLabel="l"/>
<Key android:codes="-500" android:keyLabel="" android:keyWidth="5%p" android:keyEdgeFlags="right"/>
</Row>
<Row>
<Key android:codes="-1" android:keyLabel="CAPS" android:keyWidth="15%p" android:keyEdgeFlags="left"/>
<Key android:codes="122" android:keyLabel="z"/>
<Key android:codes="120" android:keyLabel="x"/>
<Key android:codes="99" android:keyLabel="c"/>
<Key android:codes="118" android:keyLabel="v"/>
<Key android:codes="98" android:keyLabel="b"/>
<Key android:codes="110" android:keyLabel="n"/>
<Key android:codes="109" android:keyLabel="m"/>
<Key android:codes="-5" android:keyLabel="DEL" android:keyWidth="15%p" android:isRepeatable="true"/>
</Row>
<Row android:rowEdgeFlags="bottom">
<Key android:codes="-6" android:keyLabel="123?" android:keyWidth="20%p" android:keyEdgeFlags="left"/>
<Key android:codes="-300" android:keyLabel="AR"/>
<Key android:codes="32" android:keyLabel="SPACE" android:keyWidth="40%p" android:isRepeatable="true"/>
<Key android:codes="46" android:keyLabel="." android:popupKeyboard="@xml/dotoptions"/>
<Key android:codes="-4" android:keyLabel="DONE" android:keyWidth="20%p" android:keyEdgeFlags="right"/>
</Row>
</Keyboard>
以下是点击cpas时的代码:
if(Character.isLetter(code) && caps){
code = Character.toUpperCase(code);
}
答案 0 :(得分:0)
也许有更好的方法,但是如果你处理大写字母按键,你可以遍历所有键并使标签大写,如下所示:
Keyboard keyboard = keyboardView.getKeyboard();
List<Key> keys = keyboard.getKeys();
for (Key key : keys) { // NOTE: you should decide if you want to skip some keys
key.label = key.label.toString().toUpperCase();
}