Android action bar tabs are left-aligned by default, I want to align it the center of the action bar. Is there any way we can make it center?
I was able to center-align the actionbar by customizing my application theme
In my AndroidManifest.xml, I added a android:theme property:
<application
android:label="#string/app_name"
android:icon="#drawable/ic_launcher"
android:theme="#style/CustomActionBarTheme">
...
I then added a new themes.xml file to my project, and added :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarTabBarStyle">#style/MyActionBarTabBar</item>
</style>
<style name="MyActionBarTabBar">
<item name="android:gravity">center</item>
</style>
</resources>
The tabs should now be center-aligned.
EDIT:
It works only if your actionbar is displayed on 2 lines (in portrait)
You can use the ViewPagerIndicator plugin to customize your tabs.
Hope it helps!
Related
This my style page:
<resources>
<color name="for_custom">#ff4db0e8</color>
<style name="CustomTheme" parent="android:Theme.Light">
<item name="android:windowBackground">#color/for_custom</item>
<item name="android:actionBarTheme">#color/for_custom</item>
<item name="android:displayOptions">homeAsUp</item>
</style>
</resources>
And this is my manifest:
<application android:label="#string/app_name" android:icon="#mipmap/ic_launcher" android:theme="#style/CustomTheme">
action bar does not show After applying theme.Why?
What is my mistake?
If you are on Lollypop+ the default Theme is Material, which does not show the ActionBar. This is because the Material Design spec remarks the Toolbar view as the new way to keep the buttons. If you want the old style, use Theme.Holo.Light instead of just Theme.Light
I use Android actionbar and tabs and I want to change my tabs background color.
I tried to apply it to the following in my style:
Widget.AppCompat.ActionBar
Widget.AppCompat.ActionBar.TabBar
Widget.AppCompat.ActionBar.TabView
Widget.AppCompat.ActionBar.Solid
It works in all cases, but dividers (little bars between each tab) are removed at the well. How can I avoid this?
You could define a style and apply it to your app or activity:
File styles.xml:
<style name="MyHoloLightTheme" parent="#style/Theme.AppCompat.Light">
<item name="actionBarStyle">#style/ActionBarStyle</item>
....
<style name="ActionBarStyle" parent="...">
<item name="background">#color/actionBarBackgroundColor</item>
...
File color.xml:
<color name="actionBarBackgroundColor">#00ff00</color>
Apply to app in AndroidManifest.xml:
<application
...
android:theme="#style/MyHoloLightTheme"
...
Hey I'm trying to change the background of my action bar but I'm not quiet sure I understand the structure of the style files. So basically I have style.xml which is to pass on some elements a desired style. Then I've Theme.xml which is to have a group of styles in it, correct ? How do you link the two in other words how do I tell the theme I want the specified style in it ? I can't manage to change the background of the action bar so here is my code:
style.xml:
<!-- Base application theme. -->
<style name="MyActionBar" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:colorBackground">#color/color_lightBlue</item>
</style>
</resources>
theme.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyCustomTheme" parent="Theme.AppCompat.Light">
</style>
</resources>
and wtf is v11/style ?
Whether you put the attributes in styles.xml or theme.xml, they have the same effect finally if you apply the theme to your app or activity. In your AndroidManifest.xml, in order to let the theme have the effect you want, you should apply your customized theme like following to your app.
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
For some reason this setup just gives me the default action bar background colour.
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar"
parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#d73830</item>
</style>
</resources>
AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="#drawable/logo"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
...
</application>
In activity_main.xml my theme is set to 'AppTheme'.
You have wrong parent of MyActionBar.
It must be from AppCompat, like next:
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background" tools:ignore="NewApi">#color/red</item>
<item name="background">#color/red</item>
</style>
What you can do is to use hash code of colour.Here is how.Go to this web page
http://www.color-hex.com
Choose a colour you wish and after copy the code of that colour and later paste into your background section.In general lets say you want your background colour of your screen to be red so you must declare it in xml layout file like this
android:background = "#FF0508"/>
You can declare this code almost everywhere where you want to change exact things colour and for my opinion its the easiest way.Why not?you got a webpage where you can get colour code and you can use it with a single line everywhere.Delicios isn't it?
How can we make action bar and action bar tabs pure white. I am using android-support-v7-appcompat libs to support backward compatibility. style/Theme.AppCompat.Light.DarkActionBar gives pure black but style/Theme.AppCompat.Light does not give pure white.
There is no default theme that would give a white action bar. You will need to make a customized action bar for your app.
The developer docs has a good article about customizing the action bar.
https://developer.android.com/training/basics/actionbar/styling.html
These are the custom styles that you will need to alter.
res/values/themes.xml
See the android:background tag where you can set a drawable for the action bar.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#drawable/actionbar_background</item>
</style>
</resources>
Apply the theme to your app.
<application android:theme="#style/CustomActionBarTheme" ... />