我创建了一个自定义键盘,它工作正常 - 除了前两行键的预览视图显示不够高.它们的垂直位置受到父布局的约束.
这些屏幕截图说明了问题 - "0"和"8"的预览位置是好的,但对于"5"和"2",它不是:
键'0'的预览显示在按钮上方...
键'8'的预览也显示在按钮上方...
但键'5'的预览未显示在按钮上方...
键'2'的预览未显示在按钮上方...
如何克服,因此"5"和"2"的预览显示在它们各自键上方相同的距离处,与"0"和"8"相同.
这是我的keyboard.xml ...
<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/keyboard_key_preview" />
Run Code Online (Sandbox Code Playgroud)
这是我的keyboard_key_preview.xml ...
<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="@color/keyboard_preview_bg"
android:textColor="@color/keyboard_preview_fg"
android:textStyle="bold"
android:textSize="@dimen/keyboard_preview_text_size" />
Run Code Online (Sandbox Code Playgroud)
这是我的keyboard_numeric.xml布局......
<Keyboard
xmlns:android="http://schemas.android.com/apk/res/android"
android:keyWidth="33.33%p"
android:keyHeight="@dimen/keyboard_key_height"
android:horizontalGap="@dimen/keyboard_horizontal_gap"
android:verticalGap="@dimen/keyboard_vertical_gap">
<Row android:rowEdgeFlags="top">
<Key android:codes="49" android:keyLabel="1" android:keyEdgeFlags="left"/>
<Key android:codes="50" android:keyLabel="2"/>
<Key android:codes="51" android:keyLabel="3" android:keyEdgeFlags="right"/>
</Row>
<Row>
<Key android:codes="52" android:keyLabel="4" android:keyEdgeFlags="left"/>
<Key android:codes="53" android:keyLabel="5"/>
<Key android:codes="54" android:keyLabel="6" android:keyEdgeFlags="right"/>
</Row>
<Row>
<Key android:codes="55" android:keyLabel="7" android:keyEdgeFlags="left"/>
<Key android:codes="56" android:keyLabel="8"/>
<Key …Run Code Online (Sandbox Code Playgroud) 我想在键盘(Android IME)中创建一个像 Gboard 这样的搜索栏,如图所示。
Gboard 示例:

我已经在 Keyboardview.xml 上实现了一个编辑文本,如图所示。
我的实现:

main_keyboard_frame.xml
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="120dp"
android:background="#cf060610"
android:id="@+id/search_panel"
android:visibility="invisible">
<EditText
android:layout_width="match_parent"
android:layout_height="40dp"
android:hint="sdsddsd"
android:id="@+id/ed"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
但问题是当我按下edittext 2(在我的ime之外)然后我的ime打开,其中包含edittext 1,如上图所示,现在当我从我的ime中写一些东西时,它写在edittext 2而不是edittext 1上,所以我想知道这背后的问题是什么?有重点吗?或者是其他东西?
java android android-input-method custom-keyboard android-custom-keyboard