0

I have been looking for a solution to my doubt but I don't find anything sure.

Do actionbar's icons must be squares? I want put an icon in my actionBar like this: enter image description here

But the result that I obtain is this: enter image description here Because my app puts a button with rectangular dimensions in a space of squares dimensions.

I have tried the next:

<item name="android:actionButtonStyle">@style/ActionButtonStyle</item>

<style name="ActionButtonStyle" parent="@android:style/Widget.Holo.Light.ActionButton">
<item name="android:minWidth">0dip</item>
<item name="android:paddingLeft">0dip</item>
<item name="android:paddingRight">0dip</item>                  

But this does not solved my problem.

Is it possible? Thanks.

KryNaC
  • 379
  • 4
  • 21

2 Answers2

0

Yes this is possible. You can do all kinds of crazy stuff in the action bar. I advise looking at the setCustomView method of the ActionBar

Donn Felker
  • 9,553
  • 7
  • 48
  • 66
  • But, how I should make it? I have declared a RelativeLayout with an ImageView for this rectangular icon, but how I associate this image with the icon in 'onCreateOptionsMenu()'? – KryNaC Jan 19 '15 at 14:40
  • This shows you how to use it: http://stackoverflow.com/questions/12883732/how-to-display-custom-view-in-actionbar – Donn Felker Jan 19 '15 at 14:41
  • Then, if I want associate an action at this icon I have make '(ImageView) findViewById(R.id.img).onClick(){ ... }' instead of 'onOptionsItemSelected(MenuItem item){ ... } ?? – KryNaC Jan 19 '15 at 15:14
  • Please @Donn Felker, answer me! – KryNaC Jan 20 '15 at 09:26
0

Not necessarily square if you use custom view in your ActionBar. However, standard action bar icons must be 32dp.

Please refer to official documentation for more details on iconography for details.

Alexander Zhak
  • 9,140
  • 4
  • 46
  • 72