문제

I got a edit text and a save button , i want to close the keypad on clicking save button instead of pressing back key, keypad has to be closed after i enter save button. How to achieve this please help me and thanks in advance

도움이 되었습니까?

해결책

You can override onkeypress on your edittext and check if the enter was pressed and if true then hide

myEditText.setOnKeyListener(new OnKeyListener() {
    @Override
    public boolean onKey(View v, int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_ENTER) { 
                InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
        }
     return false;
    }
});

다른 팁

android set hidden the keybord on press enter (in a EditText)

i think this is what you need

if not, try using this to your text, but i didn't tested:

android:singleLine="true"

The follow solution is for the Xamarin friends...

NOTE: This is when at least a character was typed and then the 'Enter' key pressed.

private SearchView _searchView;
public override bool OnCreateOptionsMenu(IMenu menu)
{
     //Do things here... Call MenuInflater......
     _searchView.QueryTextSubmit += _searchView_QueryTextSubmit;
}

void _searchView_QueryTextSubmit(object sender, SearchView.QueryTextSubmitEventArgs e)
{
    InputMethodManager imm =  (InputMethodManager)GetSystemService(InputMethodService);
    imm.HideSoftInputFromWindow(_searchView.WindowToken, HideSoftInputFlags.None);
    e.Handled = true;
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top