【问题标题】:Minus Plus sign on soft keyboard in android app减号加号在 android 应用程序的软键盘上
【发布时间】:2012-11-19 17:03:21
【问题描述】:

我从头开始创建了一个自定义键盘,它工作正常,但我在使用 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>

谢谢 尼罗

【问题讨论】:

    标签: android unicode keyboard custom-controls


    【解决方案1】:

    嗯...我还没有找到内置键盘的解决方案。 我认为没有支持 +/- 或清除的代码。 我已经通过 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);
    
    } 
    

    谢谢

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-27
      • 2011-04-03
      • 2015-11-23
      • 2011-09-01
      相关资源
      最近更新 更多