[英]Force keyboard to show on a screen
我需要在没有EditText的屏幕上显示软键盘-只是键盘。 我对可以由软键盘控制的游戏有一个想法,但是我在stackoverflow上发现的内容-不能正常工作。
这是我的game.xml-这是该应用程序主要活动的布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".GameActivity" >
<com.vladdrummer.textmaster.Game
android:id="@+id/game"
android:layout_width="wrap_content"
android:windowSoftInputMode="adjustResize"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</RelativeLayout>
这是在Activity中的调用方式:
@Override
protected void onCreate(Bundle savedInstanceState) {
this.getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);//this suppose to force keyboard to be on screen
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON);//чтоб экран не гас
setContentView(R.layout.game);
这仅适用于纵向/垂直方向,不适用于横向/水平方向。
(以防万一,我的Game类正在扩展View类,并且正在使用画布)
但是我需要在水平模式下显示它。
还有另一种方法可以使键盘保持在屏幕上:
((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE)).toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
但这没什么用
因此,在横向模式下,我需要将软键盘贴在屏幕上
尝试在单独的read中执行以下代码。
InputMethodManager im = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
if(im != null) im.toggleSoftInput(0, InputMethodManager.SHOW_IMPLICIT);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.