Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customizing ActionBar Tabs on Android 4

I'm trying to customize Tabs on my ActionBar. I just want to align tabs to phone screen and make it stretchable for various screens. But all I get is this:

enter image description here

The code I use for the theme is this:

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name="MyTheme" parent="@android:style/Theme.Holo.Light">
        <item name="android:actionBarTabTextStyle">@style/MyActionBarTabTextStyle</item>
    </style>

    <style name="MyActionBarTabTextStyle" parent="@android:style/Widget.Holo.Light.Tab">
        <item name="android:textSize">14dip</item>
        <item name="android:padding">0dip</item>
    </style>

</resources>

Is it possible just decrease the font and get rid off those blue lines?

Thanks for help in advance.

P.S.: Also the Button acts weird. The is no text (while it should be)...

like image 974
peter.o Avatar asked Apr 22 '12 22:04

peter.o


People also ask

How can I customize my action bar in Android?

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.

Where is the action bar on my Android phone?

Android ActionBar is a menu bar that runs across the top of the activity screen in android. Android ActionBar can contain menu items which become visible when the user clicks the “menu” button.

What is tabbed action bar?

Overview. The action bar is an Android UI pattern that is used to provide a consistent user interface for key features such as tabs, application identity, menus, and search. In Android 3.0 (API level 11), Google introduced the ActionBar APIs to the Android platform.

Where is action bar in Android Studio?

Beginning with Android 3.0 (API level 11), the action bar appears at the top of an activity's window when the activity uses the system's Holo theme (or one of its descendant themes), which is the default.


2 Answers

Edit: Use ActionBarCompat in the support library.


I suggest you use Jake Wharton's ActionBarSherlock for two reasons:

  1. ActionBarSherlock is an extension of the compatibility library that facilitates the use of the action bar across all versions of Android. This means users running your application on pre-HoneyComb versions of Android will be able to use the ActionBar for navigation as well. This is preferable to both the user (since the ActionBar is awesome!) and to you (since you don't have to worry about separating the control flow of your application based on whether or not the ActionBar will be available. For instance, without a pre-HoneyComb compatible ActionBar, you might have to worry about creating multiple Activitys for a single screen... one that is optimized for usage with the ActionBar, and one that can be run on pre-HoneyComb devices.

  2. With ActionBarSherlock, styling your ActionBar is easy! I could go into detail on how to do it, but the library already comes with a LOT of sample code that illustrates how to what you are describing above.

Installing/making use of the library is very easy and is almost identical to making use of the normal ActionBar provided in the Android SDK (mostly just call getSupportActionBar() instead of getActionBar()). If you have any questions, let me know.

p.s. Also note that ActionBarSherlock provides all of the functionalities that the ViewPagerExtensions library provides and more. I would definitely recommend using the former over the latter.

like image 137
Alex Lockwood Avatar answered Oct 05 '22 06:10

Alex Lockwood


There's a brand new tool to generate the correct 9patch images for the actionbar : http://jgilfelt.github.com/android-actionbarstylegenerator/

like image 40
galex Avatar answered Oct 05 '22 07:10

galex