我正在使用 ActionBarSherlock,在 ActionBar 中,当我单击 searchIcon 时,我会显示此自定义布局。
public boolean onCreateOptionsMenu(final Menu menu) {
LayoutInflater inflater = getLayoutInflater();
final View view = inflater.inflate(R.layout.on_search_icon_clicked,null, false);
view.findViewById(R.id.search_image).setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View arg0) {
EditText searchET = (EditText) view.findViewById(R.id.search_editText);
String s = searchET.getText().toString();
Toast.makeText(getBaseContext(), "Searching for: " + s,1000).show();
}
});
menu.add("Search")
.setIcon(R.drawable.ic_search)
.setActionView(view)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
return true;
}
on_search_icon_clicked.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/search_image"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:src="@drawable/ic_search"
android:clickable="true"
android:contentDescription="@string/seach_icon" />
<EditText
android:id="@+id/search_editText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/search_image"
android:hint="@string/search"
android:singleLine="true" />
</RelativeLayout>
所以,i click on the SearchIcon
---> i get the custom layout with editText and ImageView
---> click on editText, opens softkeyboard
---> enters string and clicks the imageView
--->shows me the toast.
到这里为止都很好。
问题是:
我close the softkeyboard using device back button
---> 然后close the custom layout using ActionBar Home icon click
---> 现在click the searchIcon again, which reopens the custom layout, with editText filled with previously searched string
---> click on the editText, the softkeyboard doesn't open up
(这是问题所在)。
请帮忙,我不知道为什么它不能按预期工作。
谢谢你