目录

EditText 属性 imeActionLabel 内容未在输入法编辑区显示

目录

最近在做一个登录模块 Demo 的时候发现问题:imeActionLabel 设置的按钮文字并没有在输入法的编辑区显示。

之后,查找官方文档 EditorInfo 的 actionLabel 部分说明: {% blockquote @Android APIs https://developer.android.com/reference/android/view/inputmethod/EditorInfo.html#actionLabel %} In some cases an IME may be able to display an arbitrary label for a command the user can perform, which you can specify here. This is typically used as the label for the action to use in-line as a replacement for the “enter” key (see actionId). Remember the key where this will be displayed is typically very small, and there are significant localization challenges to make this fit in all supported languages. Also you can not count absolutely on this being used, as some IMEs may ignore this. {% endblockquote %}

这里才明白,有些输入法可能会忽略这个功能的实现。这样,当屏幕较宽的时候(一般手机横屏即可),设置的 actionLabel 属性的内容会出现在 EditText 的旁边,并显示未一个文字按钮。比如对于如下的内容:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
<android.support.design.widget.TextInputLayout
      android:id="@+id/password_container"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      app:passwordToggleContentDescription="@string/toggle_password"
      app:passwordToggleDrawable="@drawable/ic_visibility_toggle"
      app:passwordToggleEnabled="true"
      >
    <android.support.design.widget.TextInputEditText
        android:id="@+id/password"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:imeActionId="@+id/login"
        android:imeActionLabel="Sign in"
        android:inputType="textPassword"
        />
  </android.support.design.widget.TextInputLayout>

在我的手机上,竖屏的时候:

portrait.png

横屏的时候:

land.png

而且,必须注意的是:这个时候会遮盖已经设置好的密码可见性切换按钮,不论显示效果还是功能设置都十分糟糕。 目前并没有十全十美的解决办法,最好的方案是尽量不要使用 imeActionLabel 属性,仅仅使用 imeActionOptions 属性。