views:

1288

answers:

1

What I want to do is change the default "Done" label that appears in the virtual keyboard. Here's what I've tried without any luck:

mSearchInput.setImeOptions(EditorInfo.IME_ACTION_DONE);
mSearchInput.setImeActionLabel(getString(R.string.search_action_label), EditorInfo.IME_ACTION_DONE);

I am able, however, to handle a click on that button, with this:

mSearchInput.setOnEditorActionListener(new TextView.OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if (actionId == EditorInfo.IME_ACTION_DONE) {
            performSearch();
            return true;
        }
        return false;
    }
});

I'm clueless as to how I can change the label on that button at the moment.

+3  A: 

The imeActionLabel sets the label for the button that appears on the top right on full screen IME mode (i.e., when your phone is in landscape). If you want to change the button to the bottom right of the keyboard, you can pass certain flags to imeOptions.

As far as I know, for that button you're limited to a certain set of actions (see here for a full list of supported flags), but since you seem to want a search button, all you have to do is to slightly adjust your first line and use IME_ACTION_SEARCH:

mSearchInput.setImeOptions(EditorInfo.IME_ACTION_SEARCH);

Mind you, the exact appearance of that button will depend on the input method. The default Android keyboard shows a magnifier for the search flag, while the Touch Input (HTC's keyboard) seems completely unaware of that flag, still showing a return button.

mernen
That's curious. When I switch to landscape in the emulator, the soft keyboard doesn't appear anymore.Also, I noticed that the Messaging application, for example, puts a smiley (":-)") instead of the "Done" button. Does it use a custom keyboard layout, or what?Thanks for the tip, by the way.
Felix
The soft keyboard is not showing up because the emulator simulates a physical keyboard being exposed in landscape mode (just like the soft keyboard won't appear on a G1 if you flip it open). You can disable the keyboard by modifying the config.ini file for the AVD, adding `hw.keyboard=no`.As for the Messaging application, I've just checked its source, and I'm guessing the smiley is a byproduct of `inputType="textShortMessage"` and the lack of a "Send" button is due to `imeOptions="flagNoEnterAction"`, but I haven't actually tested it. Mind you, Touch Input seems to ignore both flags.
mernen