Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why have android:actionLayout and android:icon at the same time?

Tags:

android

I am reading about action bars in BusyCoder's Android guide. There is an example:

<item
    android:id="@+id/add"
    android:actionLayout="@layout/add"
    android:icon="@android:drawable/ic_menu_add"
    android:showAsAction="ifRoom"
    android:title="@string/add"/>

What is the point to have both android:actionLayout and android:icon defined? What are the conditions when the icon would show up?

Thanks for helping out Android noob

like image 896
Roman Saveljev Avatar asked Feb 07 '26 05:02

Roman Saveljev


1 Answers

What are the conditions when the icon would show up?

I can't rule out the possibility that the action bar will decide that there is not enough room for the actionLayout, but there is enough room for an action item, which would therefore show the icon. Also, with ActionBarSherlock, the icon is shown even in the overflow on Android 2.x devices, and so again if the actionLayout would be too large, the icon might get used. Also, if I used ifRoom|collapseActionView instead of just ifRoom, the icon would be used.

That being said:

  • My sample does not actually watch for this theoretical action item, should it appear, to do anything if the user clicks on it

  • I am guessing at possible action bar behavior, as I have not tried any experiments to force the action bar to decide whether there is enough room for all actionLayout-configured items

like image 143
CommonsWare Avatar answered Feb 09 '26 04:02

CommonsWare



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!