EditText 忽略 ImeActionLabel

des*_*aci 2 android android-edittext

使用三星 Galaxy Ace,当我实例化 editText 时,我尝试设置一个目前被忽略的自定义标签(没有第三方键盘)与三星 Galxy SII 相同的行为这是我用于设置的代码选项

eTHomeShare = (EditText) v.findViewById(R.id.eTHomeShare);
eTHomeShare.setImeActionLabel(getString(R.string.home_done),
            EditorInfo.IME_ACTION_UNSPECIFIED);
Run Code Online (Sandbox Code Playgroud)

这是 EditText 的 xml 定义

           <EditText 
                android:id="@+id/eTHomeShare"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center_vertical"
                android:imeActionLabel="@string/done"
                android:imeOptions="actionSend"
                android:inputType="text" />
Run Code Online (Sandbox Code Playgroud)

编辑 1

按照 CommonsWare 的建议,editText 的新 xml

           <EditText 
                android:id="@+id/eTHomeShare"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center_vertical" />
Run Code Online (Sandbox Code Playgroud)

如您所见,我刚刚从 xml 中删除了 2 行,并在我的片段的 onCreateView 中使用了

 eTHomeShare.setImeActionLabel(getString(R.string.home_done),
            EditorInfo.IME_ACTION_SEND);
Run Code Online (Sandbox Code Playgroud)

现在我看不到完成/发送按钮,(顺便说一句,我一直在使用肖像)而是输入符号,如果我删除 initViews 上的行并让原始 xml 定义,则结果相同。

编辑 2 愚蠢的错误行:android:inputType="text" 已从 xml 中删除,只需使用 initViews 上的那个就可以立即正常工作。

Com*_*are 5

有很多方法可以尝试控制操作按钮上的内容,包括:

  • imeOptions
  • imeActionLabel
  • setImeActionLabel()

哪些(如果有的话)将取决于输入法编辑器(IME,又名软键盘)的实现。理想情况下,每个 IME 都会尊重所有这些……至少,当单独使用时。

然而:

  • 指定多个时的行为未定义

  • 没有任何IME的要求,甚至一个动作按钮,更别说荣誉是您在该按钮特定标题的请求

通常,我建议在一处指定操作按钮标签。我的猜测是imeOptions最有可能得到尊重,所以如果您想要的标签是标准选项之一(例如,“发送”),请使用它。