Skip to content

Commit d9bd4f2

Browse files
committed
添加搜索工具栏
1 parent cc13b6d commit d9bd4f2

4 files changed

Lines changed: 26 additions & 1 deletion

File tree

‎PhotoGallery/.idea/misc.xml‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎PhotoGallery/app/src/main/java/com/lzwap/android/photogallery/PhotoGalleryFragment.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import android.support.v7.widget.RecyclerView;
1515
import android.util.Log;
1616
import android.view.LayoutInflater;
17+
import android.view.Menu;
18+
import android.view.MenuInflater;
1719
import android.view.View;
1820
import android.view.ViewGroup;
1921
import android.view.ViewTreeObserver;
@@ -48,6 +50,7 @@ public static PhotoGalleryFragment newInstance() {
4850
public void onCreate(@Nullable Bundle savedInstanceState) {
4951
super.onCreate(savedInstanceState);
5052
setRetainInstance(true);
53+
setHasOptionsMenu(true);
5154
//new FetchItemsTask().execute();
5255
mFetchItemsTask = new FetchItemsTask();
5356
mFetchItemsTask.execute(1);
@@ -110,6 +113,12 @@ public void onDestroy() {
110113
Log.i(TAG, "Background thread destroyed");
111114
}
112115

116+
@Override
117+
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
118+
super.onCreateOptionsMenu(menu, inflater);
119+
inflater.inflate(R.menu.fragment_photo_gallery, menu);
120+
}
121+
113122
private void setupAdapter() {
114123
if (isAdded()) {
115124
//mPhotoRecyclerView.setAdapter(new PhotoAdapter(mItems));
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<menu xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto">
4+
5+
<item android:id="@+id/menu_item_search"
6+
android:title="@string/search"
7+
app:actionViewClass="android.support.v7.widget.SearchView"
8+
app:showAsAction="ifRoom"/>
9+
10+
<item android:id="@+id/menu_item_clear"
11+
android:title="@string/clear_search"
12+
app:showAsAction="never"/>
13+
14+
</menu>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
<resources>
22
<string name="app_name">PhotoGallery</string>
3+
<string name="search">Search</string>
4+
<string name="clear_search">Clear Search</string>
35
</resources>

0 commit comments

Comments
 (0)