Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/192.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 软键盘上的搜索键出现问题_Android - Fatal编程技术网

Android 软键盘上的搜索键出现问题

Android 软键盘上的搜索键出现问题,android,Android,我使用actionbar中的搜索字段,将其引用到名为search_layout.xml的布局文件夹中的xml。在2.3.3版本的android中,出现了一个问题,例如输入文本后,键盘上第一次没有显示搜索图标。相反,我必须单击“回车”键,然后在文本字段上,然后只显示“搜索”图标。这在android的4.0.4和4.4.2等更高版本中不会发生 以下是search_layout.xml: 此xml在res>>menu>>menu.xml中引用 <item android:id="@+

我使用actionbar中的搜索字段,将其引用到名为search_layout.xml的布局文件夹中的xml。在2.3.3版本的android中,出现了一个问题,例如输入文本后,键盘上第一次没有显示搜索图标。相反,我必须单击“回车”键,然后在文本字段上,然后只显示“搜索”图标。这在android的4.0.4和4.4.2等更高版本中不会发生

以下是search_layout.xml:

此xml在res>>menu>>menu.xml中引用

<item
    android:id="@+id/action_notification"
    android:actionLayout="@layout/search_layout"
    android:icon="@drawable/ic_searchicon"
    android:orderInCategory="0"
    android:showAsAction="always|collapseActionView"
    android:title="Search"/>


通过这样做解决了此问题:

            public boolean onMenuItemActionExpand(MenuItem item) 
            {
                editsearch.clearFocus();
                editsearch.post(new Runnable() {
                    @Override
                    public void run() {
                        editsearch.requestFocus();
                        final InputMethodManager imm = (InputMethodManager) Activity_Cat_Products.this
                                .getSystemService(Context.INPUT_METHOD_SERVICE);
                        imm.showSoftInput(editsearch, InputMethodManager.SHOW_IMPLICIT);

                    }
                });
                return true;
            }
            public boolean onMenuItemActionExpand(MenuItem item) 
            {
                editsearch.clearFocus();
                editsearch.post(new Runnable() {
                    @Override
                    public void run() {
                        editsearch.requestFocus();
                        final InputMethodManager imm = (InputMethodManager) Activity_Cat_Products.this
                                .getSystemService(Context.INPUT_METHOD_SERVICE);
                        imm.showSoftInput(editsearch, InputMethodManager.SHOW_IMPLICIT);

                    }
                });
                return true;
            }