在Android自定义键盘中,如何将字母键盘更改为符号键盘? [英] In Android Custom Keyboard, how to change Alphabets Keyboard to Symbols Keyboard?

查看:326
本文介绍了在Android自定义键盘中,如何将字母键盘更改为符号键盘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将用户从字母键盘导航到符号键盘时,布局对齐方式被破坏了.默认情况下,布局采用5dp填充和用户看不到最后一列的键.

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.

注意:下面显示的图像.

Note: Images shown in below.

我使用onKey方法处理了将用户从字母键盘导航到符号键盘的按键操作

I handled Key Actions to Navigate User from Alphabets Keyboard to Symbol Keyboard in the onKey Method

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:

在Kotlin中使用setMethod在KeyboardView中更改键盘时,它会出现一些轻微的UI错误

While Change Keyboard in KeyboardView using setMethod in Kotlin, It changes with some mild UI Error

符号键盘:

注意:

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

推荐答案

键盘布局"基于百分比(不在 dp 中)绘制每个键. 因此,请在 dp

Keyboard Layout draws every key based on the percentage not in dp. So declare your key width as %p not in dp

在布局文件中

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

在资源文件中

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

这篇关于在Android自定义键盘中,如何将字母键盘更改为符号键盘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆