Cannot Change Enter Key Label For Custom Keyboard In Android
I'm designing a custom keyboard for Android. I want to have my custom label for ENTER key for some fields in my application. I used sample SoftKeyboard project for developing my ke
Solution 1:
Finally I found the solution. Instead of passing int options, we have to pass EditorInfo attribute. We pass it like bellow
@OverridepublicvoidonStartInput(EditorInfo attribute, boolean restarting)
{
super.onStartInput(attribute, restarting);
...
yourSoftKeyboard.setImeOptions(getResources(), attribute);
}
Then we implement setImeOptions like bellow:
voidsetImeOptions(Resources res, EditorInfo ei)
{
if (enterKey == null)
{
return;
}
switch (ei.imeOptions & (EditorInfo.IME_MASK_ACTION | EditorInfo.IME_FLAG_NO_ENTER_ACTION))
{
case EditorInfo.IME_ACTION_SEND:
enterKey.iconPreview = null;
enterKey.icon = null;
enterKey.label ="Send";
break;
case EditorInfo.IME_ACTION_GO:
enterKey.iconPreview = null;
enterKey.icon = null;
enterKey.label ="Go";
break;
case EditorInfo.IME_ACTION_NEXT:
enterKey.iconPreview = null;
enterKey.icon = null;
enterKey.label = "Next";
break;
case EditorInfo.IME_ACTION_SEARCH:
enterKey.icon = res.getDrawable(R.drawable.sym_keyboard_search);
enterKey.label = null;
break;
default:
enterKey.iconPreview = null;
enterKey.label = "Enter";
enterKey.icon = null;
break;
}
if (ei.actionLabel != null)
{
enterKey.iconPreview = null;
enterKey.icon = null;
enterKey.label = ei.actionLabel;
}
}
Post a Comment for "Cannot Change Enter Key Label For Custom Keyboard In Android"