List of usage examples for android.widget Toolbar.LayoutParams Toolbar.LayoutParams
public LayoutParams(int width, int height)
From source file:cx.ring.fragments.CallListFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.call_list_menu, menu); searchMenuItem = menu.findItem(R.id.menu_contact_search); dialpadMenuItem = menu.findItem(R.id.menu_contact_dial); MenuItemCompat.setOnActionExpandListener(searchMenuItem, new MenuItemCompat.OnActionExpandListener() { @Override/* www .jav a2 s . c o m*/ public boolean onMenuItemActionCollapse(MenuItem item) { dialpadMenuItem.setVisible(false); list.setAdapter(mConferenceAdapter); //listSwitcher.setDisplayedChild(0); list.setVisibility(View.VISIBLE); contactList.setAdapter(null); contactList.setVisibility(View.GONE); return true; } @Override public boolean onMenuItemActionExpand(MenuItem item) { dialpadMenuItem.setVisible(true); contactList.setAdapter(mListAdapter); //listSwitcher.setDisplayedChild(1); contactList.setVisibility(View.VISIBLE); list.setAdapter(null); list.setVisibility(View.GONE); onLoadFinished(null, mCallbacks.getService().getSortedContacts()); return true; } }); searchView = (SearchView) searchMenuItem.getActionView(); searchView.setOnQueryTextListener(this); searchView.setQueryHint(getString(R.string.searchbar_hint)); searchView.setLayoutParams( new Toolbar.LayoutParams(Toolbar.LayoutParams.MATCH_PARENT, Toolbar.LayoutParams.MATCH_PARENT)); searchView.setImeOptions(EditorInfo.IME_ACTION_GO); }
From source file:com.mendhak.gpslogger.GpsMainActivity.java
public void setupEvenlyDistributedToolbar() { //http://stackoverflow.com/questions/26489079/evenly-spaced-menu-items-on-toolbar // Use Display metrics to get Screen Dimensions Display display = getWindowManager().getDefaultDisplay(); DisplayMetrics metrics = new DisplayMetrics(); display.getMetrics(metrics);/*from w w w .j a va 2 s . c o m*/ // Toolbar Toolbar toolbar = (Toolbar) findViewById(R.id.toolbarBottom); // Add 10 spacing on either side of the toolbar toolbar.setContentInsetsAbsolute(10, 10); // Get the ChildCount of your Toolbar, this should only be 1 int childCount = toolbar.getChildCount(); // Get the Screen Width in pixels int screenWidth = metrics.widthPixels; // Create the Toolbar Params based on the screenWidth Toolbar.LayoutParams toolbarParams = new Toolbar.LayoutParams(screenWidth, Toolbar.LayoutParams.WRAP_CONTENT); // Loop through the child Items for (int i = 0; i < childCount; i++) { // Get the item at the current index View childView = toolbar.getChildAt(i); // If its a ViewGroup if (childView instanceof ViewGroup) { // Set its layout params childView.setLayoutParams(toolbarParams); // Get the child count of this view group, and compute the item widths based on this count & screen size int innerChildCount = ((ViewGroup) childView).getChildCount(); int itemWidth = (screenWidth / innerChildCount); // Create layout params for the ActionMenuView ActionMenuView.LayoutParams params = new ActionMenuView.LayoutParams(itemWidth, Toolbar.LayoutParams.WRAP_CONTENT); // Loop through the children for (int j = 0; j < innerChildCount; j++) { View grandChild = ((ViewGroup) childView).getChildAt(j); if (grandChild instanceof ActionMenuItemView) { // set the layout parameters on each View grandChild.setLayoutParams(params); } } } } }