Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在自定义键盘中弹出按键_Android_Keyboard_Keyboard Events - Fatal编程技术网

Android 在自定义键盘中弹出按键

Android 在自定义键盘中弹出按键,android,keyboard,keyboard-events,Android,Keyboard,Keyboard Events,我使用keyboardview拥有自己的键盘 工作正常,但我不能像Android键盘那样放大按键的效果 这些是使用的部件 <android.inputmethodservice.KeyboardView android:id="@+id/keyboardview" style="@style/Widget.KeyboardView" android:layout_width="fill_parent" android:lay

我使用keyboardview拥有自己的键盘

工作正常,但我不能像Android键盘那样放大按键的效果

这些是使用的部件

<android.inputmethodservice.KeyboardView
        android:id="@+id/keyboardview"
        style="@style/Widget.KeyboardView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:shadowRadius="0"
        android:visibility="visible" />


@可拉拔/纳兰贾
@可拉拔/纳兰贾
40便士
#d35400
@布局/键盘\u弹出式\u键盘
12dp
80dp
@布局/键盘\u弹出式\u键盘

XML/弹出窗口:

   <?xml version="1.0" encoding="utf-8"?>
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
    android:keyWidth="10%p"
    android:keyHeight="10%p">
</Keyboard>


我尝试过onKey方法,也是从XML开始的。但是没有成功

对于仅显示放大的预览,默认情况下,
KeyboardView
应该这样做。您不想设置
popupKeyboard
值,因为这是为长按时显示的特殊小键盘设置的

我猜你在跟踪。注意第3.3节中的这些行:

// Do not show the preview balloons
mKeyboardView.setPreviewEnabled(false);
而是将其设置为
true

完整解决方案

在活动的布局中:

xml/kb.xml

结果

按下“5”键时:


您可能还会发现,查看以下内容也很有用

我想显示keypreview onLong Press事件的keyboardview是可能的
     <Key
                android:codes="81"
                android:keyEdgeFlags="left"
                android:keyLabel="Q"
                android:popupCharacters="Q"
                android:popupKeyboard="@xml/popup" />

    etc...
// Do not show the preview balloons
mKeyboardView.setPreviewEnabled(false);
<android.inputmethodservice.KeyboardView
    android:id="@+id/keyboardview"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:keyPreviewOffset="12dp"
    android:keyPreviewLayout="@layout/kbpreview"
    android:visibility="visible" />
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:gb="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="10dp"
    android:background="@color/red"
    android:textSize="30dp" />
<?xml version="1.0" encoding="utf-8"?>
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
    android:keyWidth="12.50%p"
    android:keyHeight="10%p" >

    <Row>
        <Key android:codes="55"    android:keyLabel="7" android:keyEdgeFlags="left" />
        <Key android:codes="56"    android:keyLabel="8" />
        <Key android:codes="57"    android:keyLabel="9" />
        <Key android:codes="65"    android:keyLabel="A" android:horizontalGap="6.25%p" />
        <Key android:codes="66"    android:keyLabel="B" />
        <Key android:codes="55006" android:keyLabel="CLR" android:keyEdgeFlags="right"/>
    </Row>

    <!-- and whatever else... -->

</Keyboard>
    Keyboard mKeyboard = new Keyboard(this, R.xml.kb);

    // Lookup the KeyboardView
    KeyboardView mKeyboardView = (KeyboardView) findViewById(R.id.keyboardview);

    // Attach the keyboard to the view
    mKeyboardView.setKeyboard(mKeyboard);

    // Key listener required
    mKeyboardView.setOnKeyboardActionListener(myListener);