【问题标题】:Add a submenu in an Android Keyboard?在 Android 键盘中添加子菜单?
【发布时间】:2022-01-14 19:40:01
【问题描述】:

我正在尝试创建一个自定义 Android 键盘,只是想了解这个过程。

我比较成功,因为我现在只是学习基础知识:

我的问题是,我怎样才能从通常的键盘中实现这种效果,在我按住一个键并弹出更多选项列表的情况下?

感谢任何帮助。

【问题讨论】:

    标签: java android xml


    【解决方案1】:

    只是为了将来可能需要这个的人,主要的方法是使用 xml 键盘:

    <?xml version="1.0" encoding="utf-8"?>
    <Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
        android:keyWidth="10%p"
        android:horizontalGap="4px"
        android:verticalGap="4px"
        android:keyHeight="45dp">
    
        <Row>
            <Key android:keyLabel="q" android:popupKeyboard="@xml/qwerty_q" android:keyEdgeFlags="left"/>
            <Key android:keyLabel="w" android:popupKeyboard="@xml/qwerty_w"/>
            <Key android:keyLabel="e" android:popupKeyboard="@xml/qwerty_e"/>
            <Key android:keyLabel="r" android:popupKeyboard="@xml/qwerty_r"/>
            <Key android:keyLabel="t" android:popupKeyboard="@xml/qwerty_t"/>
            <Key android:keyLabel="y" android:popupKeyboard="@xml/qwerty_y"/>
            <Key android:keyLabel="u" android:popupKeyboard="@xml/qwerty_u"/>
            <Key android:keyLabel="i" android:popupKeyboard="@xml/qwerty_i"/>
            <Key android:keyLabel="o" android:popupKeyboard="@xml/qwerty_o"/>
            <Key android:keyLabel="p" android:popupKeyboard="@xml/qwerty_p"/>
        </Row>
    </Keyboard>
    

    然后在“xml”文件夹下创建每个相关的键盘,格式为xml:

    在弹出式键盘内格式化:

    <?xml version="1.0" encoding="utf-8"?>
    
    <Keyboard
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:keyWidth="10%p"
        android:horizontalGap="4px"
        android:verticalGap="4px"
        android:keyHeight="40dp">
    
        <Row android:gravity="center_horizontal">
            <Key android:keyLabel="s" android:keyEdgeFlags="left"/>
            <Key android:keyLabel="ſ"/>
            <Key android:keyLabel="ƨ"/>
            <Key android:keyLabel="ß"/>
            <Key android:keyLabel="σ"/>
            <Key android:keyLabel="ς"/>
        </Row>
    </Keyboard>
    

    还有一个添加弹出字符的选项,但我不确定它是否支持输入完整的字符串,如果需要输入“.com”、“.net”、&c,您可能想要这样做。

    <?xml version="1.0" encoding="utf-8"?>
    
    <Keyboard
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:keyWidth="10%p"
        android:horizontalGap="4px"
        android:verticalGap="4px"
        android:keyHeight="40dp">
    
        <Row android:gravity="center_horizontal">
            <Key android:keyLabel=".com" android:keyOutputText=".com">
            <Key android:keyLabel=".net" android:keyOutputText=".net">
            <Key android:keyLabel=".jpg" android:keyOutputText=".jpg">
            <Key android:keyLabel="·e·" android:keyOutputText="·e·"/>
        </Row>
    </Keyboard>
    

    【讨论】:

      猜你喜欢
      • 2014-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多