软键盘上的输入按钮 - Android

问题描述 投票:0回答:2

我使用单行编辑文本,因此当我单击编辑文本框时,我会得到“Go”而不是 Enter 按钮。但我想要 Enter 键代替“Go”键。我该怎么做..请有人能给出解决方案吗?

android android-edittext android-softkeyboard
2个回答
1
投票

我不确定,但你可以尝试

android:imeOptions="actionDone"
,总之你需要尝试
android:imeOptions
属性。


0
投票
    EditText editText = findViewById(R.id.editText); // Your EditText

    Button button = findViewById(R.id.button); // Your Button

    editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
    editText.setRawInputType(InputType.TYPE_CLASS_TEXT);

    editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                button.performClick(); // Imitation of pressing the button

                // Hide the keyboard after pressing
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);

                return true;
            }
            return false;
        }
    });
© www.soinside.com 2019 - 2024. All rights reserved.