簡體   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