actionbarsherlock心得

主要方法,就是標題欄菜單的設置android

@Override
        public void onActivityCreated(Bundle savedInstanceState) {
            super.onActivityCreated(savedInstanceState);
            setHasOptionsMenu(true);
        }
ide

        @Override
        public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
            // Place an action bar item for searching.
            MenuItem item = menu.add("Search");
            item.setIcon(android.R.drawable.ic_menu_search);
            item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
            SubMenu sub = menu.addSubMenu("過濾");
            sub.add(0, 1, 0, "今天");
            sub.add(0, 2, 0, "本週");
            sub.add(0, 3, 0, "本月");
            sub.add(0, 4, 0, "所有");
            sub.add(0, 5, 0, "標籤");
            sub.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
            menu.add("add").setIcon(R.drawable.add).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
            SherlockFragmentActivity activity = (SherlockFragmentActivity) getActivity();
            View searchView = SearchViewCompat.newSearchView(activity.getSupportActionBar().getThemedContext());
            if (searchView != null) {
                SearchViewCompat.setOnQueryTextListener(searchView, new OnQueryTextListenerCompat() {
                    @Override
                    public boolean onQueryTextChange(String newText) {
                     // 搜索
                        return true;
                    }
                });
                item.setActionView(searchView);
            }
        }spa

        public boolean onOptionsItemSelected(MenuItem item) {
            if (item.getTitle().equals("add")) {ci

            }
            switch (item.getItemId()) {
            case 1:      get

                break;
                      }it

            return false;
        }io

 

分清楚 SherlockFragmentActivity SherlockFragment 而且按照DEMO配合使用table

相關文章
相關標籤/搜索