android - Actionbar with customView has extra padding that cannot be removed -


having trouble getting actionbar display icons proper styling.

my customer wants actionbar has specific icons varying shades of transparency. if place icons xml file in res/menu, have no way icons lie adjacent each other , backgrounds of each icon result in vertical gaps so:

enter image description here

res/menu/global_nav.xml

<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" >  <item     android:id="@+id/menu"     android:icon="@drawable/ic_main_menu"     android:showasaction="always"     android:title="@string/nav_menu_main"/>    <item     android:id="@+id/login"     android:icon="@drawable/ic_people"     android:showasaction="always"     android:title="@string/nav_menu_login"/> <item     android:id="@+id/location"     android:icon="@drawable/ic_location"     android:showasaction="always"     android:title="@string/nav_menu_location"/> 

etc, etc.

so, created customview , placed same icons within relativelayout. makes icons line better , doesn't leave gaps between icons. can style easier, though lose ability use menus above. however, leaves gap @ bottom of row of icons above pagertitlestrip. ux image people left search icon full transparency around icon other have light color makes padding below icons noticeable. without slight transparency around them 1 never notice, customer wants padding gone.

enter image description here

res/layout/global_nav_custom.xml

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/att_blue" android:paddingbottom="-54dp" android:orientation="horizontal" >  <imageview     android:id="@+id/menu"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignparentleft="true"     android:src="@drawable/ic_main_menu" />  <imageview     android:id="@+id/search"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignparentleft="false"     android:layout_alignparentright="true"     android:src="@drawable/ic_search" />  <imageview     android:id="@+id/message"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_toleftof="@id/search"     android:src="@drawable/ic_message" />  <imageview     android:id="@+id/cart"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_toleftof="@id/message"     android:src="@drawable/ic_cart" />  <imageview     android:id="@+id/location"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_toleftof="@id/cart"     android:src="@drawable/ic_location" />  <imageview     android:id="@+id/login"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_toleftof="@id/location"     android:src="@drawable/ic_people" />  <textview     android:id="@+id/textview2"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignbottom="@+id/menu"     android:layout_marginleft="364dp"     android:layout_torightof="@+id/menu"     android:text="@string/app_name"     android:textappearance="?android:attr/textappearancelarge"     android:textcolor="@android:color/white" />  </relativelayout> 

java code

    actionbar bar = getactionbar();     bar.setdisplayoptions(actionbar.display_show_custom);      layoutinflater li = layoutinflater.from(this);     view customview = li.inflate(r.layout.global_nav_custom, null);       bar.setcustomview(customview); 

so, question a) how can style actionbar either use standard style xml menu remove vertical gaps. or b) customview solution, 4+ pixel gap @ bottom.

by way, actionbarsherlock not option company wants no 3rd party libraries

using standard action buttons

you can achieve standard action buttons using custom theme app.
note: work, icons must 32dp or less

<?xml version="1.0" encoding="utf-8"?> <resources>     <style name="myapptheme" parent="android:theme.holo.light">         <item name="android:actionbuttonstyle">@style/actionbutton</item>         <item name="android:actionbarsize">32dp</item>     </style>      <style name="actionbutton" parent="android:widget.actionbutton">         <item name="android:paddingstart">0dp</item>         <item name="android:paddingend">0dp</item>         <item name="android:paddingleft">0dp</item>         <item name="android:paddingright">0dp</item>         <item name="android:minwidth">0dp</item>     </style> </resources> 

enter image description here

don't forget edit androidmanifest set theme of activity/application ;)


using actionlayout

another way specify actionlayout each of action item. way can keep icon anyway want, , keep action bar size 48dp.

the downside have handle menu item button rather menu item, using onclicklistener or using onclick attribute of view. onclick attribute of menuitem not work.

you should display menu title when user long press item, standard action buttons.

menu.xml

<?xml version="1.0" encoding="utf-8"?> <menu     xmlns:android="http://schemas.android.com/apk/res/android">      <item         android:id="@+id/menu"         android:actionlayout="@layout/widget_main_button"         android:showasaction="always"         android:title="main"/>     <item         android:id="@+id/login"         android:actionlayout="@layout/widget_login_button"         android:showasaction="always"         android:title="login"/>     <item         android:id="@+id/location"         android:actionlayout="@layout/widget_location_button"         android:showasaction="always"         android:title="location"/> </menu> 

widget_main_button.xml

<?xml version="1.0" encoding="utf-8"?> <imagebutton     xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/menu_main_button"     android:layout_width="@dimen/action_button_width"     android:layout_height="?android:actionbarsize"     android:background="@drawable/ic_main_menu"/> 

enter image description here


a useful tool when styling android application android resource navigator jeff gilfelt. chrome extension allows navigate default android themes , styles find need change.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -