Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
302 views
in Technique[技术] by (71.8m points)

android - I want to change actionbar icon size

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 ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...