如何在 Android 键盘中同时拥有 "Return" 和 "Done" 选项
How to Have Both "Return" and "Done" Options in Android Keyboard
我有一个使用 EditText 的 android 记事本应用程序。当用户开始输入编辑文本时,我希望他们可以选择使用 "done" 按钮退出键盘或使用 "Return" 按钮转到下一行。我找不到使键盘同时包括完成和 return 按钮的方法。如果有任何方法可以实现这一点,那就太好了。
我知道一种方法是在键盘上添加一个顶部边框,其中包含一个 "Done" 按钮。我也对此进行了研究,但我无法找到如何在键盘可见时显示顶部边框。如果那是最好的方法,我也想知道该怎么做。我已经设法使用带有 adjustResize 的键盘调整屏幕上的边框大小,但我想让边框仅在键盘可见时才存在。这就是我被困的地方。
以下是我的观点:
<?xml version="1.0" encoding="utf-8"?>
<!--
The main EditText that covers the entire activity.
It is attached to the LinedEditor class which
gives it the "notepad" look.
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent">
<view
class = "com.patrickslagle.notepad.NewNote$LinedEditor"
android:id="@+id/note"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/yellow"
android:scrollbars="vertical"
android:fadingEdge="vertical"
android:gravity="top"
android:textSize="22sp"
android:textColor="@color/black"
android:paddingLeft="60dp"
android:paddingStart="60dp"
android:paddingTop= "25dp"
android:textCursorDrawable="@drawable/cursor"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<include layout="@layout/bottom_border"
android:layout_width="match_parent"
android:layout_height="44dp"
android:id="@+id/bottom_border"
android:layout_alignBottom="@+id/note"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
还有我现在的底边框:
<!--
The bottom menu bar where the user chooses actions.
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/bottom_border"
android:layout_width="match_parent"
android:layout_height="30dp"
android:orientation="horizontal"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:background="@color/yellow"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginBottom="0dp">
<ImageButton
android:contentDescription="@string/delete_button"
android:layout_width="45dp"
android:layout_height="45dp"
android:id="@+id/delete"
android:src="@drawable/ic_delete_24dp"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/bullets"
android:layout_toEndOf="@id/bullets"
android:padding="7dp"
android:layout_margin="0dp"
android:background="@color/yellow" />
<ImageButton
android:contentDescription="@string/save_button"
android:layout_width="45dp"
android:layout_height="45dp"
android:id="@+id/save"
android:src="@drawable/ic_save_24dp"
android:padding="7dp"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/mail"
android:layout_toStartOf="@+id/mail"
android:background="@color/yellow" />
<ImageButton
android:contentDescription="@string/menu_desc"
android:layout_width="45dp"
android:layout_height="45dp"
android:id="@+id/menu"
android:src="@drawable/ic_menu_24dp"
android:padding="7dp"
android:layout_margin="0dp"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/save"
android:layout_toStartOf="@+id/save"
android:background="@color/yellow" />
<ImageButton
android:contentDescription="@string/bullet"
android:layout_width="45dp"
android:layout_height="45dp"
android:id="@+id/bullets"
android:src="@drawable/ic_format_list_bulleted_24dp"
android:padding="7dp"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/mail"
android:layout_toEndOf="@+id/mail"
android:background="@color/yellow" />
<ImageButton
android:contentDescription="@string/mail_symbol"
android:layout_width="45dp"
android:layout_height="45dp"
android:id="@+id/mail"
android:src="@drawable/ic_email_24dp"
android:padding="7dp"
android:layout_centerHorizontal="true"
android:background="@color/yellow" />
<ImageButton
android:contentDescription="@string/clear"
android:layout_width="45dp"
android:layout_height="45dp"
android:id="@+id/clear_note"
android:src="@drawable/ic_clear_24dp"
android:padding="7dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:background="@color/yellow" />
</RelativeLayout>
如果有帮助的话,这是我的应用程序的屏幕截图:
根据 Google 设计指南,例如http://developer.android.com/design/patterns/navigation.html,您不需要键盘扩展:
- 设备上的后退键(硬键或软键)只会让键盘消失。
- 如果您需要其他操作,例如 "save changes",您应该在屏幕顶部放置一个操作按钮。这也可以在键盘仍然打开时单击,因此不需要额外的单击。
遵循设计规则将使您的应用更易于使用,因为它的行为与其他知名应用相似。相比之下,自带键盘布局的应用可能会让用户感到困惑。
我有一个使用 EditText 的 android 记事本应用程序。当用户开始输入编辑文本时,我希望他们可以选择使用 "done" 按钮退出键盘或使用 "Return" 按钮转到下一行。我找不到使键盘同时包括完成和 return 按钮的方法。如果有任何方法可以实现这一点,那就太好了。
我知道一种方法是在键盘上添加一个顶部边框,其中包含一个 "Done" 按钮。我也对此进行了研究,但我无法找到如何在键盘可见时显示顶部边框。如果那是最好的方法,我也想知道该怎么做。我已经设法使用带有 adjustResize 的键盘调整屏幕上的边框大小,但我想让边框仅在键盘可见时才存在。这就是我被困的地方。
以下是我的观点:
<?xml version="1.0" encoding="utf-8"?>
<!--
The main EditText that covers the entire activity.
It is attached to the LinedEditor class which
gives it the "notepad" look.
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent">
<view
class = "com.patrickslagle.notepad.NewNote$LinedEditor"
android:id="@+id/note"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/yellow"
android:scrollbars="vertical"
android:fadingEdge="vertical"
android:gravity="top"
android:textSize="22sp"
android:textColor="@color/black"
android:paddingLeft="60dp"
android:paddingStart="60dp"
android:paddingTop= "25dp"
android:textCursorDrawable="@drawable/cursor"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<include layout="@layout/bottom_border"
android:layout_width="match_parent"
android:layout_height="44dp"
android:id="@+id/bottom_border"
android:layout_alignBottom="@+id/note"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
还有我现在的底边框:
<!--
The bottom menu bar where the user chooses actions.
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/bottom_border"
android:layout_width="match_parent"
android:layout_height="30dp"
android:orientation="horizontal"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:background="@color/yellow"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginBottom="0dp">
<ImageButton
android:contentDescription="@string/delete_button"
android:layout_width="45dp"
android:layout_height="45dp"
android:id="@+id/delete"
android:src="@drawable/ic_delete_24dp"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/bullets"
android:layout_toEndOf="@id/bullets"
android:padding="7dp"
android:layout_margin="0dp"
android:background="@color/yellow" />
<ImageButton
android:contentDescription="@string/save_button"
android:layout_width="45dp"
android:layout_height="45dp"
android:id="@+id/save"
android:src="@drawable/ic_save_24dp"
android:padding="7dp"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/mail"
android:layout_toStartOf="@+id/mail"
android:background="@color/yellow" />
<ImageButton
android:contentDescription="@string/menu_desc"
android:layout_width="45dp"
android:layout_height="45dp"
android:id="@+id/menu"
android:src="@drawable/ic_menu_24dp"
android:padding="7dp"
android:layout_margin="0dp"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/save"
android:layout_toStartOf="@+id/save"
android:background="@color/yellow" />
<ImageButton
android:contentDescription="@string/bullet"
android:layout_width="45dp"
android:layout_height="45dp"
android:id="@+id/bullets"
android:src="@drawable/ic_format_list_bulleted_24dp"
android:padding="7dp"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/mail"
android:layout_toEndOf="@+id/mail"
android:background="@color/yellow" />
<ImageButton
android:contentDescription="@string/mail_symbol"
android:layout_width="45dp"
android:layout_height="45dp"
android:id="@+id/mail"
android:src="@drawable/ic_email_24dp"
android:padding="7dp"
android:layout_centerHorizontal="true"
android:background="@color/yellow" />
<ImageButton
android:contentDescription="@string/clear"
android:layout_width="45dp"
android:layout_height="45dp"
android:id="@+id/clear_note"
android:src="@drawable/ic_clear_24dp"
android:padding="7dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:background="@color/yellow" />
</RelativeLayout>
如果有帮助的话,这是我的应用程序的屏幕截图:
根据 Google 设计指南,例如http://developer.android.com/design/patterns/navigation.html,您不需要键盘扩展:
- 设备上的后退键(硬键或软键)只会让键盘消失。
- 如果您需要其他操作,例如 "save changes",您应该在屏幕顶部放置一个操作按钮。这也可以在键盘仍然打开时单击,因此不需要额外的单击。
遵循设计规则将使您的应用更易于使用,因为它的行为与其他知名应用相似。相比之下,自带键盘布局的应用可能会让用户感到困惑。