相关疑难解决方法(0)

以编程方式打开软键盘

我有一个没有子窗口小部件的活动,相应的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>
Run Code Online (Sandbox Code Playgroud)

我想在活动开始时以编程方式打开软键盘.我现在尝试的是,

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);
    }
Run Code Online (Sandbox Code Playgroud)

给我一些指导.

android android-softkeyboard

110
推荐指数
14
解决办法
12万
查看次数

标签 统计

android ×1

android-softkeyboard ×1