Testing ActionBar Background Color - android

I am starting to unit testing my Android code. However, I am facing a problem of how to test the background of ActionBar. I set the action bar color using the following:
<style name="AppBaseTheme" parent="android:Theme.Light">
<item name="android:actionBarStyle">#style/ActionBarTheme</item>
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<style name="ActionBarTheme" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#color/dark_green</item>
</style>
So, how to load the style in code and check for the background color so I can test it?

In your application manifest make sure you have android:theme="#style/AppBaseTheme"
Or whatever you decide to name your custom theme.

Related

Textview background color got changed after adding custom theme to android app

My app interface originally looked like this. "my name" is a TextView and "my button" is a button which has an image as the background. Minimum sdk is 16.
I changed the action bar color of the app by adding a custom theme. I used the code below.
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/MyTheme</item>
<!-- Customize your theme here. -->
</style>
<style name="MyTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:background">#color/com_facebook_blue</item>
</style>
Then my output came like this.
All the background color got changed to the new color of the app. I only need to change the color of the action bar.
Can anyone help me?
Try this
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>

How to set background color of android app and background of action bar

I am trying to modify my app to have a dark blue action bar with a light blue background. So far I have only been able to make the entire app dark blue. How can I modify my code to keep the action bar the color it is now but make the background with the team numbers a light blue? Please note my apps minimum API is 14.
I am currently using the following code in my styles.xml:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:background">#color/teamLightBlue</item>
</style>
<!-- Activity themes -->
<style name="Theme.Base" parent="android:Theme.Light" />
<style name="Theme.Sample" parent="Theme.Base" />
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="AppTheme">
<item name="android:actionBarStyle">#style/MyActionBarTheme</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBarTheme" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#color/teamDarkBlue</item>
</style>
If you choose to use Theme.AppCompat, you can change Action Bar's background color using:
<item name="colorPrimary">#ffffff</item>
but if you choose the Holo one, you can change that color using
<item name="android:colorPrimary">#ffffff</item>
Hope this helps.
As far as I know your code is good instead of Widget.Holo.Light.ActionBar as its not part of AppCompat v7. Use this instead
<style name="CustomActionBarTheme" parent="AppTheme">
<item name="android:actionBarStyle" tools:ignore="NewApi">#style/MyActionBarTheme</item>
<item name="actionBarStyle">#style/MyActionBarTheme</item>
</style>
<style name="MyActionBarTheme" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/teamDarkBlue</item>
<item name="background">#color/teamDarkBlue</item>
</style>
It should work fine!

Title do not appear on android action bar

I am trying to style my actionbar with background color. I have also given label in the android manifest file which shows up in the action bar. But when i try to change background color using Style.xml , it changes the background color but do not show label.
Below is the Style xml
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.ActionBar">
<item name="background">#color/actionbarcolor</item>
</style>
could you please let me know , what change i should make so that it shows label name also after applying background color.
I have applied theme "AppTheme" at application level in manifest file .
Try to add this
<style>
<item name="android:actionBarTabTextStyle">#style/AwesomeTabTextStyle</item>
</style>
<style name="AwesomeTabTextStyle" parent="#android:style/Widget.ActionBar.TabText">
<item name="android:textAppearance">#android:style/TextAppearance.Medium</item>
<item name="android:textSize">14sp</item>
<item name="android:textColor">#color/actionbar_text_color</item>
</style>

Background image in TabBar Android

I'm trying set the background image for a tabbar in my app like in this example,
Android Design in Action: Transit Apps in the minute 27:16
My code is:
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarTabBarStyle">#style/Divider</item>
<!-- Customize your theme here. -->
</style>
<style name="Divider" parent="#android:style/Widget.Holo.ActionBar.TabBar">
<item name="android:background">#drawable/ic_launcher</item>
</style>
but the picture is stretched
How do I can get the same thing ?
Regards,
racso

Android ActionBar not changing background color

I am trying to change the background color of my action bar but it doesnt change. My app is using the AppCompat theme if that affects anything.
Here is my theme that is being used. My app points to use this theme so that is not the problem
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="actionBarStyle">#style/ActionBar</item>
</style>
<!-- Action Bar Styles -->
<style name="ActionBar" parent="Widget.AppCompat.ActionBar">
<item name="android:background">#color/blue</item>
<item name="background">#color/blue</item>
</style>
In your ActionBar style, delete the android:background, only keep the background attribute. Also make sure to implement your AppTheme in the application tag or in the activities extending the action bar in your AndroidManifest.xml file. I've also added the "#style/" attribute before Widget.AppCompat since its a default style defined in the android library.
Your code should look like this :
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="actionBarStyle">#style/ActionBar</item>
</style>
<!-- Action Bar Styles -->
<style name="ActionBar" parent="#style/Widget.AppCompat.ActionBar">
<item name="background">#0000ff</item>
</style>
You can se this from code as well
ab.setBackgroundDrawable(new ColorDrawable(newcolor));
Just in case your xml is not working
According to this link, https://developer.android.com/reference/android/R.attr.html#background
it doesn't seem to take color resource, so you either give it a hex color value or create a drawable that uses the color you want. You could try the following alternative to see if it works.
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="actionBarStyle">#style/ActionBar</item>
</style>
<!-- Action Bar Styles -->
<style name="ActionBar" parent="Widget.AppCompat.ActionBar">
<item name="android:background">#0000ff</item>
<item name="background">#0000ff</item>
</style>

Categories

Resources