Customize each single Navigation Tabs separately using Actionbar java - android

i am using ActionBar to create an android app in eclipse with Tab Navigations and i would like to customize each of my tabs separately to add custom background color and icon to them. How can i set background, and icon to a tab on the ActionBar?
Thanks in advance!

When you create a new Android project/Android Activity, there are some templates you can choose from. Once of those should be for a tabbed navigation activity using ActionBar tabs. Somewhere in the generated code you'll see it's creating instances of ActionBar.Tab and adding them to the ActionBar. You can call setIcon() on the ActionBar.Tabs.
For theme customization, I recommend you use this website, it will generate all the necessary drawables and xml resources, and you can just drop those all into your project. ActionBar Style Generator

I just found a workaround for this problem. I'm still unable to customize each tab separately, but i can load a drawable background to the Navigation Tab Bar in the XML;
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="android:Theme.Light">
<item name="android:backgroundStacked">#drawable/tab_bg</item>
<item name="android:height">60dp</item>
</style>
The result is the following, which is exactly what i wanted;
http://i.imgur.com/DB9LRwD.png

Related

Theme.AppCompat.Light.Dialog theme remove default app bar

I am trying to add a custom tool bar to this activity which uses the theme
Theme.AppCompat.Light.Dialog but the main issue is to remove the already existing default tool bar and put the custom tool bar on top.
I have tried creating new styles parenting the Theme.AppCompat.Light.Dialog theme with no luck.
Also the default tool bar doesn't have the settings popup icon as in the custom tool bar. Any ideas that you might have will surely be appreciated.
Found a Solution
Changed the style of the dialog by
<style name="Theme.AppCompat.Light.Dialog.custom">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
This style extends the Theme.AppCompat.Light.Dialog theme

Change Action bar color for different tab

I'm trying to use the new Android Lollipop support library. I set my primary color in my theme to set the color of the action bar. No i'm wondering if i can change this color at runtime. In my case it should change when another tab is selected.
you can try this
ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#0000ff")));
Make a function and call this function when you change the tab
AppCompat does not use the android: prefixed attributes for the Material Theme color palette items per the migration guide to v21 by the author of AppCompat. Instead, just use the names themselves:
<style name="AppTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/primaryDef</item>
<item name="colorPrimaryDark">#color/primaryDarkDef</item>
<item name="colorAccent">#color/primaryDef</item>
<item name="android:navigationBarColor">#color/primaryDarkDef</item>
<item name="android:activatedBackgroundIndicator">#drawable/defbg</item>
</style>
The Action Bar will be colored by colorPrimary.
just found a nice pice of code, which also handles different version.
changeColor

Any easy way to change Android Action Bar "selected" color?

I'm able to change a lot of colors through using the Android style documentation from here and looking at the source here and here.
Using what I learned above, I was able to change the ActionBar.TabBar, ActionBar.TabText, and ActionBar.TabView, but I don't know what that little highlight is called. Searching for a holo blue in the android source code from above also didn't help.
I still don't know if there is any way in styles.xml to specify that "blue" highlight color to be changed.
EDIT:
I know that I can use the the action bar style generator, but I'm looking at if I can set the color of it in code (whether it be java or xml). I would not like to have to generate a new drawable for this purpose.
The easiest way You can have is to use Android Action Bar Style Generator to easily theme your action bar and tabs.
You can also refer ActionBar Documents for a customized ActionBar.Something like
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActivityTheme" parent="#android:style/Theme.Holo">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<!-- other activity and action bar styles here -->
</style>
<!-- style for the action bar backgrounds -->
<style name="MyActionBar" parent="#android:style/Widget.Holo.ActionBar">
<item name="android:background">#drawable/ab_background</item>
<item name="android:backgroundStacked">#drawable/ab_background</item>
<item name="android:backgroundSplit">#drawable/ab_split_background</item>
</style>
</resources>
Alternatively you can try ActionBarSherlock.There is one sample available in the library named "Style ActionBar".Using this you can change ActionBar tabs underline color.
I also see a useful link in a comment to your question.You are good to go after referring all these links.
Hope this helps.

Android ActionBar Loading Issue

I've having an issue with my actionBar that I've implemented.The screenshots below that I've provided will highlight the problem that I'm facing.Currently when I start my MainActivity,I've a navigation drawer and an actionBar.But the problem I'm facing is that there a split-second loading of the actionbar where it's in its original white color as shown below.
And then it immediately proceeds on changing its color as I've set as shown belown.
My issue is,how do I prevent the ActionBar for being "white" for a quick split second before it changes color?How do I let the actionBar be immediately green the moment the Activity starts?Thank you for the help :)
If you target for minimum API level 11 , you can change ActionBar's background color by defining custom style, as:
<resources>
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">ANY_HEX_COLOR_CODE</item>
</style>
And, set "MyTheme" as theme for application / activity. It will not show that split second problem.
Are you setting the color in your activity?
Perhaps you can try using Styles instead?

Styling none actionbar-tabs

In my application I'm using a mix of the actionbar tabs and the "old" TabWidget. I have no problems styling the actionbar tabs using a custom style theme.
<style name="MyTheme" parent="#android:style/Theme.Holo">
<item name="android:logo">#drawable/logo</item>
<item name="android:actionBarTabStyle">#style/MyActionBarStyle</item>
<item name="android:tabWidgetStyle">#style/MyTabStyle</item>
</style>
The TabWidgetStyle doesn't seem to have the same effect on the "old" TabWidget though. I've been trying to change the blue bottom tab-indicator color to red without any success. Does anyone have any tips on how to do this? Do I have to create an a separate tab class and use that as the tab indicator?
Thanks.

Categories

Resources