0

我从头开始创建了一个自定义键盘,它工作正常,但我有 2 个键的 2 个问题。

C - 清除键,当用户按下时清除文本 +/- - 在数字前添加/删除减号。

所有的键都适用于 android 代码,当我查看 SDK 示例时,它们使用的是 Unicode(而不是 Android 代码)。它在示例中工作正常,但在我的应用程序中它没有做任何事情。

<?xml version="1.0" encoding="utf-8"?>
<Keyboard 
 xmlns:android="http://schemas.android.com/apk/res/android"
android:keyWidth="25%p" 
android:horizontalGap="0px"
android:verticalGap="0px" 
android:keyHeight="40dip"
>

<Row>
    <Key android:codes="14" android:keyLabel="7" android:keyEdgeFlags="left"/>
    <Key android:codes="15" android:keyLabel="8"/>
    <Key android:codes="16" android:keyLabel="9"/>
    <Key android:codes="67"  android:keyIcon="@drawable/keyboard_delete"
        android:iconPreview="@drawable/keyboard_delete"
        android:keyEdgeFlags="right"/>

</Row>

<Row>
    <Key android:codes="11" android:keyLabel="4" android:keyEdgeFlags="left"/>
    <Key android:codes="12" android:keyLabel="5"/>
    <Key android:codes="13" android:keyLabel="6"/>
    <Key android:codes="" android:keyLabel="C" android:keyEdgeFlags="right"/>
</Row>

<Row>
    <Key android:codes="8" android:keyLabel="1" android:keyEdgeFlags="left"/>
    <Key android:codes="9" android:keyLabel="2"/>
    <Key android:codes="10" android:keyLabel="3"/>
    <Key android:codes="69" android:keyLabel="±" android:keyEdgeFlags="right"/>
</Row>
<Row>
    <Key android:codes="7" android:keyLabel="0" android:keyWidth="50%p"/>
    <Key android:codes="56" android:keyLabel="."/>
</Row>
</Keyboard>

谢谢尼罗

4

1 回答 1

0

嗯......我还没有找到内置键盘的解决方案。我认为没有支持 +/- 或清除的代码。我已经通过 Listener 解决了

    public void onKey(int primaryCode, int[] arg1) {
// TODO Auto-generated method stub
long eventTime = System.currentTimeMillis();
KeyEvent event = new KeyEvent(eventTime, eventTime,
    KeyEvent.ACTION_DOWN, primaryCode, 0, 0, 0, 0,
    KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE);

 if(primaryCode==177)
 {
 pressedC_Button();
 }
else
 if(primaryCode==241)
{
  pressedNegative_button();
}

dispatchKeyEvent(event);

} 

谢谢

于 2012-12-02T23:59:57.617 回答