gpt4 book ai didi

android - 如何覆盖键盘 ondown 按钮?

转载 作者:太空狗 更新时间:2023-10-29 14:11:24 25 4
gpt4 key购买 nike

enter image description here

当用户关闭键盘上的向下按钮时,我想隐藏我的编辑文本..

尝试-1

我试过 KeycodeBack 但这不起作用

 @Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {


MainActivity.editText2.setVisibility(View.INVISIBLE) ;

return true;
}

return super.onKeyDown(keyCode, event);
}

尝试-2

我试过 editorActionListener 但也没有帮助

editText2.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
boolean handled = false;

if (actionId == EditorInfo.IME_ACTION_DONE ||event.getKeyCode() == KeyEvent.KEYCODE_BACK||event.getAction()==KeyEvent.KEYCODE_ENTER
) {
MainActivity.editText2.setVisibility(VISIBLE);

}
return handled ;
}
});

但是 Event 总是 null

最佳答案

在你的 Activity 中你可以捕捉到这个事件

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);


// Checks whether a hardware keyboard is available
if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) {
Toast.makeText(this, "keyboard visible", Toast.LENGTH_SHORT).show();
} else if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES) {
Toast.makeText(this, "keyboard hidden", Toast.LENGTH_SHORT).show();
}
}

并且在您的 list 中,您应该在配置更改中添加这些更改。

    <activity
android:configChanges = "keyboard|keyboardHidden" // and if you have any other config changes.

关于android - 如何覆盖键盘 ondown 按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27753734/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com