Refresh/Update Default Action Button in Android Keyboard

Nathan Sokalski 4,121 Reputation points
2021-03-15T20:19:48.727+00:00

I have a RecyclerView that contains EditText(s). The default (from what I can tell) Action Button (android:imeOptions) is either actionNext (when there are 1 or more items after the focused EditText) or actionDone (when the last EditText is focused). One of the controls in each row of my RecyclerView is a Button that adds another row (which obviously includes an EditText) after the current one. However, if the user clicks this Button while the keyboard is open, the Action Button does not get updated until the currently focused EditText loses & regains focus. How can I force the Action Button to be updated appropriately (sort of like closing & reopening the keyboard)?

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,298 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. JarvanZhang 23,951 Reputation points
    2021-03-16T07:06:34.45+00:00

    However, if the user clicks this Button while the keyboard is open, the Action Button does not get updated until the currently focused EditText loses & regains focus.

    Hi, njsokalski. When clicking the button, will it change the focus on the control? The Action Button depends on the editText which is being focused. If you want to change the style of the action button, please set the new added editText to be focused.

    For example:

    private void Btn_Click(object sender, EventArgs e)
    {
        EditText edit = new EditText(this);
        var _params = new LinearLayout.LayoutParams(LayoutParams.MatchParent, LayoutParams.WrapContent);
        edit.LayoutParameters = _params;
    
        edit.InputType = Android.Text.InputTypes.ClassText;
    
        edit.ImeOptions = Android.Views.InputMethods.ImeAction.Search;
        layout.AddView(edit);
    
        edit.RequestFocus();
    }