Android TabBar Style not scaling to full screen - android

This is my current TabBar Style
<style name="SM5Theme" parent="android:style/Theme.Holo.Light">
<item name="android:actionBarTabStyle">#style/SM5Theme.ActionBarTabStyle</item>
<item name="android:actionBarTabBarStyle">#style/SM5Theme.ActionBarTabBarStyle</item>
<item name="android:actionBarTabTextStyle">#style/SM5Theme.ActionBarTabTextStyle</item>
</style>
<style name="SM5Theme.ActionBarTabStyle" parent="android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#drawable/tab_bar_background</item>
<item name="android:gravity">center</item>
<item name="android:dividerPadding">0dp</item>
<item name="android:showDividers">middle</item>
<item name="android:textColor">#color/tab_highlight</item>
</style>
<style name="SM5Theme.ActionBarTabTextStyle" parent="#android:style/Widget.Holo.Light.ActionBar.TabBar">
<item name="android:textColor">#color/tab_textcolor</item>
</style>
<style name="SM5Theme.ActionBarTabBarStyle" parent="#android:style/Widget.Holo.Light.ActionBar.TabView">
</style>
TabBarBackground:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="#drawable/tab_bar_background_non_selected"/>
<item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="#drawable/tab_bar_background_selected"/>
<item android:state_selected="false" android:state_pressed="true" android:drawable="#color/tab_highlight"/>
<item android:state_selected="true" android:state_pressed="true" android:drawable="#drawable/tab_bar_background_selected_pressed"/>
</selector>
tab_bar_background_selected:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="-3dp" android:left="-3dp" android:right="-3dp">
<shape android:shape="rectangle">
<stroke android:color="#color/tab_bottom_bar" android:width="3dp"/>
<solid android:color="#color/tab_background_selected"/>
</shape>
</item>
</layer-list>
This works satisfactory on generating the Tab Theme and underline color. However, the problem is it's doesn't scale all the way.
How can I solve this? I don't want to use sherlock or the android theme generator.

Related

Custom spinner UI with arrow and vertical line

I am trying to implement a spinner with a custom layout (not the spinner item layout), the outer layout. I want it to look like this:
http://imgur.com/a/U6RzU
I searched stackoverflow and google, but couldn't figure out how to come up with this (beside putting the whole picture as a background)
Thanks a lot in advance
Edit
This is what I tried:
styles.xml
<style name="spinner">
<item name="android:layout_marginTop">6dp</item>
<item name="android:layout_marginBottom">6dp</item>
<item name="android:layout_marginLeft">0dp</item>
<item name="android:layout_marginRight">0dp</item>
<item name="android:padding">10dp</item>
<item name="android:background">#drawable/spinner_bg</item>
<item name="android:popupBackground">#color/red</item>
<item name="android:textSize">15sp</item>
</style>
spinner_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item>
<shape>
<gradient android:angle="90" android:endColor="#ff0000"
android:startColor="#ff0000" android:type="linear" />
<stroke android:width="0.33dp" android:color="#0fb1fa" />
<corners android:radius="0dp" />
<padding android:bottom="3dp" android:left="3dp" android:right="3dp" android:top="3dp" />
</shape>
</item>
<item android:right="5dp">
<bitmap android:gravity="center_vertical|right" android:src="#drawable/arrow_white_down" />
</item>
</layer-list>
</item>
</selector>
where arrow_white_down is a png of a tiny white arrow (like the one in the link)
I solved it by using a RelativeLayout with the spinner and an image (arrow) beside it, it doesn't look really good in spinnerMode="dropdown" but this is the best I could do
layout
<RelativeLayout
android:id="#+id/spinner_container"
style="#style/spinner_container">
<Spinner
android:id="#+id/spinner"
style="#style/spinner"
android:layout_toLeftOf="#+id/spinner_image"
android:layout_toStartOf="#+id/spinner_image" />
<ImageView
android:id="#+id/spinner_image"
style="#style/spinner_image" />
</RelativeLayout>
styles.xml
<style name="spinner_container">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">35dp</item>
<item name="android:orientation">horizontal</item>
<item name="android:layout_marginTop">6dp</item>
<item name="android:layout_marginBottom">6dp</item>
<item name="android:layout_marginLeft">0dp</item>
<item name="android:layout_marginRight">0dp</item>
<item name="android:background">#color/red</item>
</style>
<style name="spinner">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_margin">0dp</item>
<item name="android:layout_alignParentLeft">true</item>
<item name="android:layout_alignParentStart">true</item>
<item name="android:padding">5dp</item>
<item name="android:textColor">#color/white</item>
<item name="android:background">#color/red</item>
<item name="android:popupBackground">#color/red</item>
<item name="android:textSize">15sp</item>
</style>
<style name="spinner_image">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">match_parent</item>
<item name="android:layout_margin">5dp</item>
<item name="android:padding">0dp</item>
<item name="android:layout_alignParentRight">true</item>
<item name="android:layout_alignParentEnd">true</item>
<item name="android:adjustViewBounds">true</item>
<item name="android:src">#drawable/bc_spinner_arrow</item>
</style>
where bc_spinner_arrow is a transparent pic of a white arrow and a vertical line (like the one in the question)

ViewPagerIndicator doesn't show underline in Tab

I want to make simple TabPagerIndicator, but It doesn't show a underline, I use xml to change the style. This is my xml style file:
<!-- Application theme. -->
<style name="AppTheme" parent="#style/Theme.AppCompat.Light">
<item name="vpiTitlePageIndicatorStyle">#style/CustomTitlePageIndicator</item>
<item name="vpiUnderlinePageIndicatorStyle">#style/CustomUnderlinePageIndicator</item>
<item name="vpiTabPageIndicatorStyle">#style/CustomTabPageIndicator</item>
</style>
<style name="CustomTabPageIndicator" parent="Widget.TabPageIndicator">
<item name="android:background">#color/fondo_activity</item>
<item name="android:textAppearance">#style/CustomTabPageIndicator.Text</item>
<item name="android:textColor">#FF555555</item>
<item name="android:textSize">14sp</item>
<item name="android:dividerPadding">10dp</item>
<item name="showDividers">middle</item>
<item name="android:paddingLeft">8dp</item>
<item name="android:paddingRight">8dp</item>
<item name="android:fadingEdge">horizontal</item>
<item name="android:fadingEdgeLength">8dp</item>
</style>
<style name="CustomTabPageIndicator.Text" parent="android:TextAppearance.Medium">
<item name="android:typeface">monospace</item>
</style>
<style name="CustomUnderlinePageIndicator">
<item name="selectedColor">#FFCC0000</item>
<item name="android:background">#FFCCCCCC</item>
<item name="fadeLength">1000</item>
<item name="fadeDelay">1000</item>
</style>
<style name="CustomTitlePageIndicator">
<item name="android:background">#18FF0000</item>
<item name="footerColor">#FFAA2222</item>
<item name="footerLineHeight">1dp</item>
<item name="footerIndicatorHeight">3dp</item>
<item name="footerIndicatorStyle">underline</item>
<item name="android:textColor">#AA000000</item>
<item name="selectedColor">#FF000000</item>
<item name="selectedBold">true</item>
</style>
In this picture you can see how it is shown (the red line on the top is part of the action bar)
Does anyone knows where is the error and How can I solve it?
Best.
You can set the underline with the background property. Set it to an XML drawable that defines which drawables/9-patches are used to draw the different states.
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Non focused states -->
<item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="#drawable/vpi__tab_unselected_holo" />
<item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="#drawable/vpi__tab_selected_holo" />
<!-- Focused states -->
<item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="#drawable/vpi__tab_unselected_focused_holo" />
<item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="#drawable/vpi__tab_selected_focused_holo" />
<!-- Pressed -->
<!-- Non focused states -->
<item android:state_focused="false" android:state_selected="false" android:state_pressed="true" android:drawable="#drawable/vpi__tab_unselected_pressed_holo" />
<item android:state_focused="false" android:state_selected="true" android:state_pressed="true" android:drawable="#drawable/vpi__tab_selected_pressed_holo" />
<!-- Focused states -->
<item android:state_focused="true" android:state_selected="false" android:state_pressed="true" android:drawable="#drawable/vpi__tab_unselected_pressed_holo" />
<item android:state_focused="true" android:state_selected="true" android:state_pressed="true" android:drawable="#drawable/vpi__tab_selected_pressed_holo" />
</selector>

How to change selected tab Color or Font color for ActionbarTab?

I am using xml to change background of selected tab using Actionbar Tab with view pager
code is below,
style.xml
<!-- Custom theme. -->
<style name="MyTheme" parent="android:style/Theme.Holo.Light">
<item name="android:windowActionBar">true</item>
<item name="android:actionBarSize">30dp</item>
<item name="android:icon">#drawable/logo</item>
<item name="android:actionBarTabTextStyle">#style/Widget.Holo.TabWidget</item>
<!-- <item name="android:actionBarTabTextStyle">#style/customTabBar</item> -->
</style>
<style name="Widget.Holo.TabWidget" parent="android:style/Widget.TabWidget">
<item name="android:tabStripLeft">#null</item>
<item name="android:tabStripRight">#null</item>
<item name="android:tabStripEnabled">true</item>
<!-- <item name="android:divider">#android:attr/dividerVertical</item> -->
<item name="android:showDividers">middle</item>
<item name="android:dividerPadding">8dip</item>
<item name="android:divider">#android:attr/dividerVertical</item>
<item name="android:dividerHeight">10dp</item>
<item name="android:measureWithLargestChild">true</item>
<item name="android:textSize">16sp</item>
<item name="android:textStyle">bold</item>
<item name="android:background">#drawable/tab_bg_selector</item>
</style>
tab_bg_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- Active tab -->
<item android:drawable="#drawable/tab_bg_selected" android:state_focused="false" android:state_pressed="false" android:state_selected="true"/>
<!-- Inactive tab
<item android:drawable="#drawable/tab_bg_unselected" android:state_focused="false" android:state_pressed="false" android:state_selected="false"/>
-->
<item android:drawable="#android:color/transparent" android:state_pressed="true"/>
<!-- Selected tab (using d-pad) -->
<item android:drawable="#android:color/transparent" android:state_focused="true" android:state_pressed="false" android:state_selected="true"/>
tab_bg_selected.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:centerColor="#7F7F7F"
android:endColor="#696969"
android:startColor="#A8A8A8" />
</shape>
It shows me changed color but color is changes for text background only I want to change for whole Tab selected
See below image,
These custom styles work fine for me
<style name="MyActionBarTabStyle" parent="#style/Widget.AppCompat.Light.ActionBar.TabView">
<item name="android:tabStripEnabled">false</item>
<item name="android:footerDividersEnabled">false</item>
<item name="android:background">#drawable/tab_selector</item>
<item name="background">#drawable/tab_selector</item>
</style>
And
<style name="MyActionBarTabTextStyle" parent="#style/Widget.AppCompat.Light.ActionBar.TabText">
<item name="android:textColor">#color/tab_text_color</item>
<item name="android:textSize">12sp</item>
<item name="android:gravity">fill_horizontal</item>
</style>
I hope it works fine for u as well
Take a look to this: Styling Tabs

ActionBar with AppCompat actionBarItemBackground not working

I am trying to change the color of an item when it pressed. I used the actionBarItemBackground item in the action bar style, but nothing happens.. The color not changed...
Here my code:
<style name="ActionBarStyle" parent="#style/Widget.AppCompat.ActionBar.Solid">
<item name="android:background">#color/actionbar_background</item>
<item name="titleTextStyle">#style/ActionBarStyle.Title</item>
<item name="actionBarItemBackground">#drawable/action_bar_item_selector</item>
<item name="android:actionBarItemBackground" tools:ignore="NewApi">#drawable/action_bar_item_selector</item>
</style>
And the selector:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/pressed_item" android:state_focused="true"/>
<item android:drawable="#drawable/pressed_item" android:state_pressed="true"/>
<item android:drawable="#android:color/transparent"/>
</selector>
And the drawable:
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="#FF0000"/>
</shape>
What is worng? Someone?
actionBarItemBackground isn't inherit of Widget.ActionBar. You should be placing it in your root theme, wherever you apply your ActionBarStyle, but not in your ActionBarStyle. So, something like:
<style name="Your.Theme" parent="#style/Theme.AppCompat">
<item name="actionBarStyle">#style/ActionBarStyle</item>
<item name="android:actionBarStyle">#style/ActionBarStyle</item>
<item name="actionBarItemBackground">#drawable/action_bar_item_selector</item>
<item name="android:actionBarItemBackground" tools:ignore="NewApi">#drawable/action_bar_item_selector</item>
</style>

How to change the color of tab 'underbar' in actionbarsherlock

Ok i'm loosing more sanity then ever. I can't find/understand how to style the damn thing.
I managed to change the background of the tab itself but I can't cahnge the color of the bar under the selected tab.
How to change it from blue to something.
My styles.xml unfortunately I have very bad understanding of how it works
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Styled" parent="Theme.Sherlock.Light">
<item name="actionBarTabStyle">#style/Widget.Styled.ActionBarTab</item>
<item name="android:actionBarTabStyle">#style/Widget.Styled.ActionBarTab</item>
<item name="actionBarTabBarStyle">#style/Widget.Styled.ActionBarTabBar</item>
<item name="android:actionBarTabBarStyle">#style/Widget.Styled.ActionBarTabBar</item>
<item name="actionBarTabTextStyle">#style/myText</item>
<item name="android:actionBarTabTextStyle">#style/myText</item>
</style>
<style name="Widget.Styled.ActionBarTab" parent="Widget.Sherlock.Light.ActionBar.TabView">
<!-- <item name="background">#drawable/startbcg</item>
<item name="android:background">#drawable/startbcg</item>
<item name="backgroundSplit">#drawable/bg_striped_split</item>
<item name="android:backgroundSplit">#drawable/bg_striped_split</item>
-->
</style>
<style name="Widget.Styled.ActionBarTabBar" parent="Widget.Sherlock.Light.ActionBar.TabBar">
<item name="background">#drawable/startbcg</item>
<item name="android:background">#drawable/startbcg</item>
<item name="backgroundSplit">#drawable/bg_striped_split</item>
<item name="android:backgroundSplit">#drawable/bg_striped_split</item>
</style>
<style name="myText" parent="Widget.Sherlock.Light.ActionBar.TabText">
<item name="android:textAppearance">#android:style/TextAppearance.Medium</item>
<item name="android:textColor">#android:color/primary_text_dark</item>
<item name="android:textSize">10sp</item>
</style>
<style name="myTextInv" parent="Widget.Sherlock.Light.ActionBar.TabText.Inverse">
<item name="android:textAppearance">#android:style/TextAppearance.Medium</item>
<item name="android:textColor">#android:color/primary_text_dark</item>
<item name="android:textSize">10sp</item>
</style>
</resources>
Bonus question: where I can find what properties (like background) certain stuff has.
Use ActionbarStyleGenerator to style the Actionbar. This is by far the simplest and most intuitive way.
How to:
Use the UI to select colors for different items
Once done click on "DOWNLOAD .ZIP"
The ZIP file contains resource files that you have to copy in your project res/layout and
res/drawableXXXX folders
I found that for the background it's better to copy the drawables (9 patches and xml) found on the Android SDK res directory and change it to have the color you like.
They use a background with the bottom bar included, so I don't think it's possible to change the bottom bar alone.
Here's what I have, working with green color for the bottom bar:
<style name="customTabStyle" parent="Widget.Sherlock.ActionBar.TabView">
<item name="android:showDividers">none</item>
<item name="android:measureWithLargestChild">true</item>
<!-- This was a copy from the sdk drawable -->
<item name="android:background">#drawable/tab_indicator</item>
<item name="background">#drawable/tab_indicator</item>
<item name="android:gravity">center</item>
<item name="android:textStyle">normal</item>
</style>
<style name="customTabBar" parent="Widget.Sherlock.ActionBar.TabBar">
<item name="android:showDividers">middle</item>
<item name="android:divider">#drawable/tab_divider</item>
<item name="divider">#drawable/tab_divider</item>
<item name="android:dividerPadding">10dip</item>
<item name="android:background">#drawable/tab_bg</item>
</style>
The tab indicator looks like this:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Non focused states -->
<item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="#drawable/tab_unselected" />
<item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="#drawable/tab_selected" />
<!-- Focused states -->
<item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="#drawable/tab_unselected_focused" />
<item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="#drawable/tab_selected_focused" />
<!-- Pressed -->
<!-- Non focused states -->
<item android:state_focused="false" android:state_selected="false" android:state_pressed="true" android:drawable="#drawable/tab_unselected_pressed" />
<item android:state_focused="false" android:state_selected="true" android:state_pressed="true" android:drawable="#drawable/tab_selected_pressed" />
<!-- Focused states -->
<item android:state_focused="true" android:state_selected="false" android:state_pressed="true" android:drawable="#drawable/tab_unselected_pressed" />
<item android:state_focused="true" android:state_selected="true" android:state_pressed="true" android:drawable="#drawable/tab_selected_pressed" />
</selector>
I hope it helps!

Categories

Resources