Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I want to change actionbar icon size

Tags:

I tried to use this code

<item         android:id="@+id/male_button"         android:layout_width="46dp"         android:layout_height="56dp"         android:layout_gravity="right"         android:icon="@drawable/icon_male"         android:showAsAction="always"         android:title="i"/>     <item         android:id="@+id/female_button"         android:layout_width="46dp"         android:layout_height="56dp"         android:layout_gravity="right"         android:icon="@drawable/icon_female"         android:showAsAction="always"         android:title="i"/> 

and I changed android:layout_width="46dp" to android:layout_width="30dp" but I still have the same size the desired image is

enter image description here

and I now have this

enter image description here

How can I change the icons to be as the first picture ?

like image 468
Mohammed Subhi Sheikh Quroush Avatar asked Mar 08 '13 17:03

Mohammed Subhi Sheikh Quroush


People also ask

How do I change the size of my taskbar on Android?

You can set the height here android:minHeight="? attr/actionBarSize" in your XML. Use height and not minHeight.

How do I customize my action bar?

This example demonstrate about how to create a custom action bar in Android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.


2 Answers

To reduce the space between actions icons, in your styles.xml you need to create a actionButtonStyle and referencing it your main theme (ex: "AppTheme").

1st step (put the two sentences):

<style name="AppTheme" parent="Theme.AppCompat.Light">   ...   <item name="android:actionButtonStyle">@style/myActionButtonStyle</item>   <item name="actionButtonStyle">@style/myActionButtonStyle</item>   ... </style> 

2nd step (the parameter "android:width" is the great secret):

<style name="myActionButtonStyle" parent="Widget.AppCompat.ActionButton">     <item name="android:minWidth">30dp</item>     <item name="android:maxWidth">48dp</item>     <item name="android:width">38dp</item> </style> 

enjoy it

like image 71
jmtsilva69 Avatar answered Oct 03 '22 00:10

jmtsilva69


private String[] tabnames; final int[] ICONS = new int[] {         R.drawable.a,         R.drawable.b,         R.drawable.c,} tabnames = getResources().getStringArray(R.array.tabnames); 

Those are the arrays made up here and in res/values/strings of your drawable names and your tab names

actionBar = getActionBar();     for (int i=0; i < tabnames.length; i++)     { 

Every time we get a tabname we add an icon for it

        Drawable dr = getResources().getDrawable(ICONS[i]);         Bitmap bitmap = ((BitmapDrawable) dr).getBitmap();         Drawable d = new BitmapDrawable(getResources(),          Bitmap.createScaledBitmap(bitmap, 50, 50, true)); 

Then we change get icon from array and make it a drawable with whatever size we want and add it to the actionbar.

    actionBar.addTab(actionBar.newTab().setText(tabnames[i])                              .setIcon(d)                              .setTabListener(this));     } 
like image 32
SmulianJulian Avatar answered Oct 02 '22 22:10

SmulianJulian