Android键盘按键覆盖

sag*_*dar 13 android overlay

我很好奇如何在某些按钮或按键上实现以下叠加,如下图所示?我正在实现自定义键盘......同样需要这个东西.

在此输入图像描述

编辑:

所以,我已经使用Gridview实现了如下的键盘.

在此输入图像描述

现在,我试图在默认键盘上放置一些叠加(点击).

谢谢 :)

MAB*_*MAB 6

您正在寻找的是"关键预览"我假设您正在使用KeyboardView创建自定义键盘.您可以通过调用setPreviewEnabled(boolean previewEnabled)来启用键预览,它应该是这样的:mKeyboardView.setPreviewEnabled(true);

编辑:

我认为此链接将帮助您实施并详细解释我的目标.

首先为键盘创建一个布局,通常它只包含一个keyboardView:

<?xml version="1.0" encoding="UTF-8"?>
    <android.inputmethodservice.KeyboardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/keyboard"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:keyPreviewLayout ="@layout/preview" />
Run Code Online (Sandbox Code Playgroud)

然后为预览创建另一个布局:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:background="#ffff00"   
    android:textStyle="bold"
    android:textSize="30sp">    
</TextView>
Run Code Online (Sandbox Code Playgroud)

之后你就可以在你的情况下设计你的键盘:

<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="49" android:keyLabel="1" android:keyEdgeFlags="left"/>
        <Key android:codes="50" android:keyLabel="2"/>
        <Key android:codes="51" android:keyLabel="3"/>
    </Row>
    <Row>
        <Key android:codes="52" android:keyLabel="4"/>
        <Key android:codes="53" android:keyLabel="5"/>
        <Key android:codes="54" android:keyLabel="6"/>
   </Row>
   <Row>
        <Key android:codes="55" android:keyLabel="7"/>
        <Key android:codes="56" android:keyLabel="8"/>
        <Key android:codes="57" android:keyLabel="9"/>
   </Row>
</Keyboard>
Run Code Online (Sandbox Code Playgroud)

最后在你的java代码中,你可以给keyboardView充气,或者如果它包含在片段或活动布局中,你可以通过它获取它.并设置您设计的键盘.

kv = (KeyboardView)getLayoutInflater().inflate(R.layout.keyboard, null);
keyboard = new Keyboard(this, R.xml.numeric);
kv.setKeyboard(keyboard);
kv.setOnKeyboardActionListener(this);
Run Code Online (Sandbox Code Playgroud)

祝你好运.