EditText ignores the ImeActionLabel

非 Y 不嫁゛ 提交于 2019-12-11 03:56:04

问题


Using a Samsung Galaxy Ace, when i instantiate the editText i try and set a custom label that is being ignored at the moment (no third-party keyboard) same behaviour on a Samsung Galxy SII This is the code i'm using for setting the options

eTHomeShare = (EditText) v.findViewById(R.id.eTHomeShare);
eTHomeShare.setImeActionLabel(getString(R.string.home_done),
            EditorInfo.IME_ACTION_UNSPECIFIED);

This is the xml definition of the EditText

           <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" />

EDIT 1

New xml for editText as CommonsWare suggested

           <EditText 
                android:id="@+id/eTHomeShare"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center_vertical" />

As you can see i just removed the 2 lines from the xml, and in the onCreateView of my fragment i use the

 eTHomeShare.setImeActionLabel(getString(R.string.home_done),
            EditorInfo.IME_ACTION_SEND);

Now i cannot see the Done/Send button, (btw i'm always working on Portrait) but instead the Enter symbol, the same result if i remove the lines on initViews and let the original xml definition.

EDIT 2 Dumb mistake the line: android:inputType="text" was removed from the xml, just using the one on initViews worked fine at once.


回答1:


There are many ways to try to control what goes on the action button, including:

  • imeOptions
  • imeActionLabel
  • setImeActionLabel()

Which, if any, of those will work will depend upon the implementation of the input method editor (IME, a.k.a., soft keyboard). Ideally, each IME will honor all of them... at least, when used individually.

However:

  • The behavior when you specify it more than one is undefined

  • There is no requirement of any IME to even have an action button, let alone honor your request for a particular caption on that button

In general, I recommend specifying the action button label in one spot. My guess is that imeOptions is most likely to be honored, so if your desired label is one of the standard options (e.g., "send"), use that.



来源:https://stackoverflow.com/questions/23528644/edittext-ignores-the-imeactionlabel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!