繁体   English   中英

Android软键盘动态OK / Enter键

[英]Android soft keyboard dynamic OK/Enter key

我的应用程序中有一个EditText字段,我希望软键盘默认显示一个OK按钮。 我还希望当我按下Shift键以允许创建新行时,将OK键切换为默认的Enter键。 我没有办法做到这一点。 现在我只显示OK按钮,使用

edit.setImeOptions(EditorInfo.IME_ACTION_DONE);

在一行上。 我需要的是与主屏幕“添加快速笔记”字段中显示在Google Keep应用中的键盘相同的键盘

我从Android AOSP来源查看了Compose活动并进行了构建:

我将此类复制到测试项目中(包名称com.example.test):

https://android.googlesource.com/platform/packages/apps/UnifiedEmail/+/5b8799a/src/com/android/mail/compose/EnterSubject.java

然后创建此布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

    <com.example.test.EnterSubject
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView1"
        android:inputType="textEmailSubject|textAutoCorrect|textCapSentences|textImeMultiLine|textMultiLine"
        android:imeOptions="actionDone|flagNoExtractUi|flagNoFullscreen"
        android:layout_below="@+id/textView1"
        android:layout_marginTop="18dp"
        android:ems="10" >

        <requestFocus />
    </com.example.test.EnterSubject>

</RelativeLayout>

这基本上是该文件的一个重构的版本: https://android.googlesource.com/platform/packages/apps/UnifiedEmail/+/5b8799a/res/layout/compose_subject.xml并且此文件: HTTPS://android.googlesource .com / platform / packages / apps / UnifiedEmail / + / 5b8799a / res / values / styles.xml

结果是:按下Shift键会将下一个按钮变成Enter按钮。

暂无
暂无

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

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