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中引用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="@+
<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;
}