我正在使用ActionBarSherlock,在ActionBar中我有這個自定義佈局,當我點擊searchIcon時出現。點擊EditText不顯示軟鍵盤
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
(這裏的問題)。
請幫助,我不知道爲什麼它不按預期工作。
謝謝
能否請您解釋一下,爲什麼我得到這個問題,正是你解決方案呢? –
其實這不行,我相信。因爲,在我的例子R.id.search_image開關塊中的R.id.menu_search沒有起作用,因爲它不在菜單項中,它只會在我點擊searchIcon時出現(這是實際的菜單項)。 –
否否,menu_search是您搜索菜單項的ID。 menu.add(「Search」) - >嘗試爲這個菜單項設置id。 – Wayne