简体   繁体   English

在 Android 自定义键盘中,如何将字母键盘更改为符号键盘?

[英]In Android Custom Keyboard, how to change Alphabets Keyboard to Symbols Keyboard?

While Navigate User from Alphabets Keyboard to Symbols Keyboard, Layout Alignment gets spoiled.在将用户从字母键盘导航到符号键盘时,布局对齐被破坏了。 By Default, Layout takes 5dp padding & User can't see the Last Column Keys.默认情况下,布局采用 5dp 填充,用户看不到最后一列键。

Note: Images shown in below.注:图片如下所示。

I handled Key Actions to Navigate User from Alphabets Keyboard to Symbol Keyboard in the onKey Method我在 onKey 方法中处理了将用户从字母键盘导航到符号键盘的关键操作

override fun onKey(primaryCode: Int, keyCodes: IntArray?) {
when (primaryCode) {
        KEYCODE_ALPHABETS -> {
            keyboardView?.keyboard = Keyboard(this, R.xml.keyboard)
        }

        KEYCODE_SYMBOLS_1 -> {
            keyboardView?.keyboard = Keyboard(this, R.xml.keyboard_symbols_1)
        }

        KEYCODE_SYMBOLS_2 -> {
            keyboardView?.keyboard = Keyboard(this, R.xml.keyboard_symbols_2)
        }
 }

} }

Pls Suggest is there any other way to change keyboard (or) what I've done wrong请建议有没有其他方法可以更改键盘(或)我做错了什么

What I faced is shown below.我遇到的情况如下所示。 Alphabets Keyboard:字母键盘: 在此处输入图像描述

While Change Keyboard in KeyboardView using setMethod in Kotlin, It changes with some mild UI Error在 Kotlin 中使用 setMethod 在 KeyboardView 中更改键盘时,它会随着一些轻微的 UI 错误而改变

Symbols Keyboard:符号键盘: 在此处输入图像描述

Note:笔记:

  • Symbols Keyboard has no issue.符号键盘没有问题。 Bcz We tried to have it as a Primary Keyboard to inflate at very first time. Bcz 我们试图在第一时间将其作为主键盘进行充气。 It has no issue at that time.当时没有问题。
  • Issue is in Keyboard Change portion (onKey Method).问题出在键盘更改部分(onKey 方法)。 Alphabets Keyboard also not fully compatible while changing Keyboard字母键盘在更换键盘时也不完全兼容

Keyboard Layout draws every key based on the percentage not in dp .键盘布局根据不在dp中的百分比绘制每个键。 So declare your key width as %p not in dp所以声明你的键宽为%p而不是dp

In Layout file在布局文件中

<Row
            android:horizontalGap="@fraction/key_horizontal_ten_keys_gap"
            android:keyWidth="@fraction/ten_keys_key_width"
            android:rowEdgeFlags="top">
</Row>

In Resource file在资源文件中

<fraction name="ten_keys_key_width">8.8%p</fraction>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM