How to resize the Android toolbar menu icon.

How to resize a menu item on an Android toolbar? The menus are currently very small, and I want to increase the size. If anyone knows, please help me find a solution.

app_bar.xml

<?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/primaryColor" android:minHeight="?attr/actionBarSize" android:paddingTop="@dimen/app_bar_top_padding" android:theme="@style/ToolBarStyle"/> 

styles.xml

 <resources xmlns:android="http://schemas.android.com/apk/res/android"> <style name="AppTheme" parent="AppTheme.Base"> </style> <!-- Application theme. --> <style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar"> <item name="colorPrimary">@color/primaryColor</item> <item name="colorPrimaryDark">@color/primaryColorDark</item> <item name="colorAccent">@color/accentColor</item> <item name="colorControlHighlight">@color/primary_high_light</item> <!-- <item name="textColorPrimary">@color/ColorPrimaryText</item> --> </style> <style name="ToolBarStyle" parent="ThemeOverlay.AppCompat.Dark"> <item name="android:textColorPrimary">#ffffff</item> </style> <style name="option" parent="Theme.AppCompat.Light"> </style> <style name="Dialog" parent="Base.Theme.AppCompat.Light.Dialog"> </style> 

menu_option.xml

 <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <item android:id="@+id/homes" android:title="homes" android:icon="@drawable/ic_action_home1" app:showAsAction="always"/> <item android:id="@+id/profilepreview" android:title="ProfilePreview" android:icon="@drawable/profile" app:showAsAction="always"/> <item android:id="@+id/findPeople" android:title="findPeople" android:icon="@drawable/ic_action_search1" app:showAsAction="always"/> <item android:id="@+id/log" android:title="log" android:icon="@drawable/ic_action_logout1" app:showAsAction="always"/> </menu> 

MainActivity.java

 public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu_option, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.profilepreview: startActivity(new Intent(this, ProfilePreview.class)); return true; case R.id.homes: mFragment = new HomeFragment(); break; case R.id.findPeople: mFragment = new FindFriendsFragment(); break; case R.id.log: M.logOut(this); mIntent = new Intent(this, LoginActivity.class); finish(); } if (mFragment != null && mIntent == null) { mFragmentManager = getFragmentManager(); mFragmentManager.beginTransaction() .replace(R.id.frameContainer, mFragment).commit(); } else { startActivity(mIntent); mIntent = null; }return super.onOptionsItemSelected(item); } 
+6
source share
2 answers

I ran into this problem, and the only workaround I could was to use smaller images. The 24dp size of the icons here ( https://design.google.com/icons ) fits nicely into my toolbar.

0
source

You can create your own layout and add it as your actionlayout. Also make sure that you do not add an icon to the menu.xml file.

 <item android:id="@+id/homes" android:title="homes" app:actionLayout="@layout/your_custom_layout" app:showAsAction="always"/> 

Then give min_height in your custom layout.

0
source

All Articles