我有一个没有子部件的活动,相应的xml文件是,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/myLayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:focusable="true"
>
</LinearLayout>
我想以编程方式打开软键盘,而activity获取start.and,这是我之前尝试过的,
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (inputMethodManager != null) {
inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}
给我一些指导。
发布于 2011-04-11 13:31:39
我使用以下几行代码在onclick事件中手动显示了软键盘,键盘是可见的。
InputMethodManager inputMethodManager =
(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.toggleSoftInputFromWindow(
linearLayout.getApplicationWindowToken(),
InputMethodManager.SHOW_FORCED, 0);
但是当活动打开时,我仍然无法打开它,所以有什么解决方案吗?
发布于 2011-10-13 22:15:24
在清单文件中,尝试将以下内容添加到<activity>
中,以便在活动启动时显示键盘:
android:windowSoftInputMode="stateVisible"
这将使键盘在活动启动时变为可见。
有关更多选项,请查看documentation。
发布于 2011-04-11 14:49:42
请遵循以下代码。我相信你的问题会得到解决的。
if (imm != null){
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
}
https://stackoverflow.com/questions/5593053
复制相似问题