如何prevent软键盘从不断出现在我的活动?我的、出现在、键盘、prevent

2023-09-06 02:50:30 作者:拜拜、爱过

我正在写一个运行在全屏横屏模式,并具有放置在窗口的左下角和右下角的按钮,一个Android游戏。问题是,这些按钮之一(在许多手机)旁边的菜单按钮,所以玩家可能会意外地preSS菜单代替。

如果是pressed简单,我只是暂停游戏,并显示在游戏菜单中。这里没有问题。

但如果按钮时较长,安卓打开软键盘底部的屏幕的一半。因为它得到的方式,并在此活动完全没用,我想禁用它。

我尝试以下方法。

经InputMethodManager

从:Hide软键盘上的活动,没有任何键盘操作

由于我只有一个图( GLSurfaceView )我在尝试这样做我的 Activity.onCreate()

  InputMethodManager IMM =((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE));
imm.hideSoftInputFromInputMethod(glSurfaceView.getApplicationWindowToken(),0);
 

它不工作:软键盘仍然出现在菜单上长期preSS

经的Andr​​oidManifest.xml中

从:How从以往任何时候都即将在我的整个应用程序停止了android软键盘

我说这我的清单:

 <活动
    机器人:windowSoftInputMode =stateAlwaysHidden
>
 
键盘数字键打不出来 三个方法来搞定

难道一个很大的什么为好。

所以......是甚至有一种方式?怎么样?

解决方案   

但如果按钮被按下较长,   Android的打开软键盘上   屏幕底部的一半。

你有什么手机?你确定?我从来没有一次看到这种情况发生,我只是尝试过了,它不能在我的手机正常工作。

此外,这听起来像一个用户的问题。不要试图颠覆用户。如果用户真的想在你的应用程序中打开键盘,你应该让他们,如果它是无用的,他们会打回来了,它就会消失。

一个多关注的问题,应该是你的按钮是如此接近的菜单按钮。

I'm writing an Android game that runs in fullscreen landscape mode, and has buttons placed at the bottom left and bottom right of the window. The problem is that one of these buttons is (on many phones) right next to the Menu button, so the player might accidentally press Menu instead.

If it is pressed briefly, I simply pause the game and show the in-game menu. No problem there.

But if the button is held down longer, Android opens up the soft keyboard on the bottom half of the screen. Since it gets in the way, and is completely useless in this Activity, I would like to disable it.

I tried the following approaches.

Via InputMethodManager

From: Hide soft keyboard on activity without any keyboard operations

Since I have only one view (a GLSurfaceView) I tried this in my Activity.onCreate():

InputMethodManager imm = ((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE));
imm.hideSoftInputFromInputMethod(glSurfaceView.getApplicationWindowToken(), 0);

It doesn't work: the soft keyboard still comes up on Menu long-press.

Via the AndroidManifest.xml

From: How to stop the android soft keyboard from ever coming up in my entire application

I added this to my manifest:

<activity 
    android:windowSoftInputMode="stateAlwaysHidden"
>

Does a great deal of nothing as well.

So... is there even a way? How?

解决方案

But if the button is held down longer, Android opens up the soft keyboard on the bottom half of the screen.

What phone do you have? Are you sure? I've never once seen that happen and I just tried it and it doesn't work on my phone.

Also, that sounds like a user problem. Don't try to subvert the user. If the user REALLY wants to open a keyboard in your app, you should let them and if it's useless, they'll hit back and it will go away.

A more concerning issue should be that your buttons are so close to the menu buttons.