當前位置: 首頁>>代碼示例>>Java>>正文


Java MenuItemCompat類代碼示例

本文整理匯總了Java中android.support.v4.view.MenuItemCompat的典型用法代碼示例。如果您正苦於以下問題:Java MenuItemCompat類的具體用法?Java MenuItemCompat怎麽用?Java MenuItemCompat使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MenuItemCompat類屬於android.support.v4.view包,在下文中一共展示了MenuItemCompat類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: restoreActionViewStates

import android.support.v4.view.MenuItemCompat; //導入依賴的package包/類
public void restoreActionViewStates(Bundle states) {
    if (states != null) {
        SparseArray<Parcelable> viewStates = states.getSparseParcelableArray(getActionViewStatesKey());
        int itemCount = size();
        for (int i = 0; i < itemCount; i++) {
            MenuItem item = getItem(i);
            View v = MenuItemCompat.getActionView(item);
            if (!(v == null || v.getId() == -1)) {
                v.restoreHierarchyState(viewStates);
            }
            if (item.hasSubMenu()) {
                ((SubMenuBuilder) item.getSubMenu()).restoreActionViewStates(states);
            }
        }
        int expandedId = states.getInt(EXPANDED_ACTION_VIEW_ID);
        if (expandedId > 0) {
            MenuItem itemToExpand = findItem(expandedId);
            if (itemToExpand != null) {
                MenuItemCompat.expandActionView(itemToExpand);
            }
        }
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:24,代碼來源:MenuBuilder.java

示例2: onCreateOptionsMenu

import android.support.v4.view.MenuItemCompat; //導入依賴的package包/類
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    /*簡單查詢*/
    final MenuItem item = menu.findItem(R.id.action_search);
    mSearchView = (SearchView) MenuItemCompat.getActionView(item);

    mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            paraMap.put("keyWord", query);
            showLoading();
            refresh = true;
            presenter.getData(1, SIZE, paraMap);
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {

            return false;
        }
    });
    return true;
}
 
開發者ID:liuyongfeng90,項目名稱:JKCloud,代碼行數:26,代碼來源:OpportunityListActivity.java

示例3: onCreateOptionsMenu

import android.support.v4.view.MenuItemCompat; //導入依賴的package包/類
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    final MenuItem item = menu.findItem(R.id.action_search);
    SearchView mSearchView = (SearchView) MenuItemCompat.getActionView(item);
    mSearchView.setIconifiedByDefault(true);
    mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            if (shouldShowFAQ)
                ((Searchable) currentFragment).setSearchText(newText);
            return true;
        }
    });
    return super.onCreateOptionsMenu(menu);
}
 
開發者ID:w568w,項目名稱:fuckView,代碼行數:22,代碼來源:MainActivity.java

示例4: onOptionsItemSelected

import android.support.v4.view.MenuItemCompat; //導入依賴的package包/類
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();


    // Fetch and store ShareActionProvider
    mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item);

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        startActivity(new Intent(App.getAppContext(),Settings.class));
        return true;
    }else  if (id == R.id.action_favorite) {
       favourite(post);
    }else  if (id == R.id.action_share) {
        shareTextUrl();
    }
    return super.onOptionsItemSelected(item);
}
 
開發者ID:jamesddube,項目名稱:LaravelNewsApp,代碼行數:23,代碼來源:PostActivity.java

示例5: onCreateOptionsMenu

import android.support.v4.view.MenuItemCompat; //導入依賴的package包/類
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.share, menu);

    MenuItem item = menu.findItem(R.id.action_share);
    ShareActionProvider shareAction = (ShareActionProvider) MenuItemCompat.getActionProvider(item);

    Intent send = new Intent();
    send.setAction(Intent.ACTION_SEND);
    send.putExtra(Intent.EXTRA_TEXT, text.toString());
    send.setType("text/plain");
    if(shareAction != null) {
        shareAction.setShareIntent(send);
    }

    return super.onCreateOptionsMenu(menu);
}
 
開發者ID:IMSmobile,項目名稱:Fahrplan,代碼行數:19,代碼來源:ConnectionActivity.java

示例6: onCreateOptionsMenu

import android.support.v4.view.MenuItemCompat; //導入依賴的package包/類
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.ride_menu, menu);

    // store action provider
    shareMenuItem = menu.findItem(R.id.menu_item_share);
    shareMenuItem.setVisible(false);
    shareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(shareMenuItem);

    // Create share intent
    shareFileIntent = new Intent();
    shareFileIntent.setAction(Intent.ACTION_SEND);
    shareFileIntent.setType("text/csv");
    shareFileIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    setShareIntent(shareFileIntent);

    return true;
}
 
開發者ID:ponewheel,項目名稱:android-ponewheel,代碼行數:19,代碼來源:RideDetailActivity.java

示例7: onCreateOptionsMenu

import android.support.v4.view.MenuItemCompat; //導入依賴的package包/類
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.poem_toolbar, menu);

    favoriteItem = menu.findItem(R.id.action_addToFavorites);
    if (presenter.isFavorite()){
        favoriteItem.setIcon(R.drawable.ic_star_full);
    }

    MenuItem item = menu.findItem(R.id.action_share);

    ShareActionProvider mShareActionProvider =
            (ShareActionProvider) MenuItemCompat.getActionProvider(item);
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setType("text/plain");
    shareIntent.putExtra(Intent.EXTRA_TEXT, presenter.getPoemContentString());
    mShareActionProvider.setShareIntent(shareIntent);
    return true;
}
 
開發者ID:PaulKlinger,項目名稱:Sprog-App,代碼行數:21,代碼來源:PoemActivity.java

示例8: onPrepareOptionsMenu

import android.support.v4.view.MenuItemCompat; //導入依賴的package包/類
@Override
public boolean onPrepareOptionsMenu(Menu menu) {

  boolean res = super.onPrepareOptionsMenu(menu);

  MenuItem searchItem = menu.findItem(R.id.action_search);
  SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);

  searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
    @Override
    public boolean onQueryTextSubmit(String query) {
      getWebViewCoordinator().onQueryByText(query);
      return true;
    }

    @Override
    public boolean onQueryTextChange(String newText) {
      return false;
    }
  });

  return res;
}
 
開發者ID:azmedien,項目名稱:kolibri-android,代碼行數:24,代碼來源:PrototypeActivity.java

示例9: onCreateOptionsMenu

import android.support.v4.view.MenuItemCompat; //導入依賴的package包/類
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main_menu, menu);
    MenuItem search = menu.findItem(R.id.search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(search);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override public boolean onQueryTextSubmit(String query) {
            getSupportActionBar().setSubtitle("found: "+mAdapter.getItemCount());
            return true;
        }
        @Override public boolean onQueryTextChange(String newText) {
            if (mAdapter != null) {
                mAdapter.getFilter().filter(newText);
            }
            return true;
        }
    });
    menu.findItem(R.id.action_settings).setIntent(new Intent(this,SettingsActivity.class));
    return true;
}
 
開發者ID:AlexeyZatsepin,項目名稱:CP-Tester,代碼行數:21,代碼來源:MainActivity.java

示例10: fillApplicationList

import android.support.v4.view.MenuItemCompat; //導入依賴的package包/類
private void fillApplicationList() {
    // Get recycler view
    final RecyclerView rvApplication = (RecyclerView) findViewById(R.id.rvApplication);
    rvApplication.setHasFixedSize(true);
    rvApplication.setLayoutManager(new LinearLayoutManager(this));

    // Get/set application list
    new AsyncTask<Object, Object, List<Rule>>() {
        @Override
        protected List<Rule> doInBackground(Object... arg) {
            return Rule.getRules(ActivityMain.this);
        }

        @Override
        protected void onPostExecute(List<Rule> result) {
            if (running) {
                if (searchItem != null)
                    MenuItemCompat.collapseActionView(searchItem);
                adapter = new RuleAdapter(result, ActivityMain.this);
                rvApplication.setAdapter(adapter);
            }
        }
    }.execute();
}
 
開發者ID:shivam141296,項目名稱:Android-Firewall,代碼行數:25,代碼來源:ActivityMain.java

示例11: onCreateOptionsMenu

import android.support.v4.view.MenuItemCompat; //導入依賴的package包/類
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.latest_menu, menu);
    getMenuInflater().inflate(R.menu.filter_menu, menu);

    MenuItem searchViewItem = menu.findItem(R.id.filter_keyword);
    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchViewItem);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            filter.filter("K:" + searchView.getQuery());
            searchView.clearFocus();
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            filter.filter("K:" + searchView.getQuery());
            return false;
        }
    });
    return true;
}
 
開發者ID:CMPUT301W17T08,項目名稱:Moodr,代碼行數:24,代碼來源:LatestActivity.java

示例12: onCreateOptionsMenu

import android.support.v4.view.MenuItemCompat; //導入依賴的package包/類
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the options menu from XML
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.options_menu, menu);

    SearchManager searchManager = (SearchManager)
            getSystemService(Context.SEARCH_SERVICE);
    MenuItem searchMenuItem = menu.findItem(R.id.menu_search);
    SearchView searchView = (SearchView) searchMenuItem.getActionView();

    searchView.setSearchableInfo(searchManager.
            getSearchableInfo(getComponentName()));
    searchView.setOnQueryTextListener(this);
    MenuItemCompat.setOnActionExpandListener(searchMenuItem, this);

    return true;
}
 
開發者ID:10clouds,項目名稱:InifiniteRecyclerView,代碼行數:19,代碼來源:MainActivity.java

示例13: onCreateOptionsMenu

import android.support.v4.view.MenuItemCompat; //導入依賴的package包/類
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);

    // Inflate the menu and configure the media router action provider.
    getMenuInflater().inflate(R.menu.media_route_menu_item, menu);

    // Attach the MediaRouteSelector to the menu item
    MenuItem mediaRouteMenuItem = menu.findItem(R.id.media_route_menu_item);
    MediaRouteActionProvider mediaRouteActionProvider =
            (MediaRouteActionProvider)MenuItemCompat.getActionProvider(
                    mediaRouteMenuItem);
    // Attach the MediaRouteSelector that you built in onCreate()
    mediaRouteActionProvider.setRouteSelector(mSelector);

    // Return true to show the menu.
    return true;
}
 
開發者ID:tgbMedia,項目名稱:Android-app,代碼行數:19,代碼來源:VideoPlayerActivity.java

示例14: onCreateOptionsMenu

import android.support.v4.view.MenuItemCompat; //導入依賴的package包/類
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    /*簡單查詢*/
    final MenuItem item = menu.findItem(R.id.action_search);
    mSearchView = (SearchView) MenuItemCompat.getActionView(item);

    mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            Intent intent = new Intent("Msg_KeyWord");
            intent.putExtra("keyWord", query);
            sendBroadcast(intent);
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {

            return false;
        }
    });
    return true;
}
 
開發者ID:liuyongfeng90,項目名稱:JKCloud,代碼行數:25,代碼來源:SystemReportActivity.java

示例15: getFocus

import android.support.v4.view.MenuItemCompat; //導入依賴的package包/類
private void getFocus() {
    getView().setFocusableInTouchMode(true);
    getView().requestFocus();
    getView().setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {
                if (MenuItemCompat.isActionViewExpanded(search)) {
                    MenuItemCompat.collapseActionView(search);
                    return true;
                } else
                    return false;
            }
            return false;
        }
    });
}
 
開發者ID:li-yu,項目名稱:FakeWeather,代碼行數:18,代碼來源:BusFragment.java


注:本文中的android.support.v4.view.MenuItemCompat類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。