Android Studio 1.1.0. SDK 22 Installed&Compiled, SDK 17 Target (I suppose it's not relevant, because issue occurs also on preview in IDE).
I started playing with Holo theme action bar styling and ran into an issue, involving background color. This is my styles.xml:
<resources>
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:background">#ff0d3200</item>
<item name="android:actionBarStyle">#style/BarTheme</item>
</style>
<style name="BarTheme" parent="android:Widget.Holo.ActionBar">
<item name="android:background">#443322</item>
</style>
</resources>
And this is output. I want app title's background color to be the same as action bar's. As I've said, it's the same on the preview, so I don't think it's because my phone(SDK17) or emulator. Overflow button behaves the same way, there just isn't any in this case.
I tried setting android:titleTextStyle in BarTheme to this style:
<style name="TitleTheme" parent="android:TextAppearance.Holo">
<item name="android:background">#443322</item>
</style>
But it didn't change a thing. What do I do to overcome this?
try ,
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">value</item>
<item name="android:titleTextStyle">#style/TitleColor</item>
</style>
<style name="TitleColor" parent="android:TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">value</item>
</style>
Due to David's input I solved my problem myself. I had to set windowBackground, instead of background in AppTheme. I'm not sure what is the exact difference, but it works properly. Remember not to change attribute in your BarTheme, because it won't work with windowBackground. Therefore correct styles.xml file is:
<resources>
<color name="bcColor">#ff0d3200</color>
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:windowBackground">#color/bcColor</item>
<item name="android:actionBarStyle">#style/BarTheme</item>
</style>
<style name="BarTheme" parent="android:Widget.Holo.ActionBar">
<item name="android:background">#443322</item>
</style>
</resources>
Note that color has to be defined as resource in this case and cannot be hardcoded. The clean way to do this is create colors.xml in values folder and define all colors there.
Related
I'm trying to change the Contextual Action Bar style using this snippet
<style name="AppTheme.Reader" parent="AppTheme">
<item name="android:actionModeStyle">#style/AppTheme.ActionMode</item>
<item name="actionModeStyle">#style/AppTheme.ActionMode</item>
</style>
<style name="AppTheme.ActionMode" parent="Widget.AppCompat.ActionMode">
<item name="background">#color/white</item>
<item name="titleTextStyle">#style/AppTheme.ActionMode.Title</item>
<item name="subtitleTextStyle">#style/TextAppearance.AppCompat.Widget.ActionMode.Subtitle</item>
</style>
And setting the theme in the right activity
android:theme="#style/AppTheme.Reader"
Then I've used a
TextView.setCustomSelectionActionModeCallback()
To intercept the selected text, but when it comes up the CAB it has the default style and seems that my custom hasn't been applied.
Where am I wrong?
Try to use the latest support lib (as of now: v23.4.0). Depends where your parent "AppTheme" inherits from, it may or may not work but if you try to inherit from the "AppCompat" theme the following should work and once you see the white background you can fill in the rest of the attributes:
<style name="AppTheme" parent="Theme.AppCompat">
<item name="actionModeStyle">#style/ActionModeTheme</item>
</style>
<style name="ActionModeTheme" parent="#style/Widget.AppCompat.ActionMode">
<item name="background">#color/white</item>
</style>
Of course assuming <color name="white">#fff</color> is defined in colors.xml
I saw a lot of modern beautiful apps in the Play Store that use image as background. I decided to use this solution in my application. I develop for minimum API 21 Android 5.0. I prepared image 1920x1080 for xxhdpi Nexus 5 AVD.
I use material light theme. Here is my modified theme definition xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Material.Light">
<!-- Customize your theme here. -->
<item name="android:colorPrimary">#color/colorPrimary</item>
<item name="android:colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="android:colorAccent">#color/colorAccent</item>
<item name="android:background">#drawable/parquet</item>
<item name="android:actionBarStyle">#style/transparentActionBar</item>
<item name="android:statusBarColor">#android:color/transparent</item>
</style>
<style name="transparentActionBar" parent="android:Widget.Material.Light.ActionBar">
<item name="android:background">#android:color/transparent</item>
</style>
When I run application I see that each view uses its own scaled copy of theme image. My custom defined style 'transparentActionBar' has no effect on action bar. Only behind status bar I see something like original image. Is it possible to define all views transparency via XML to make visible only screen background image? If no, tell please what is right approach to the solution of this problem.
Regards.
This code does exact what I want
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Material.Light">
<!-- Customize your theme here. -->
<item name="android:colorPrimary">#color/colorPrimary</item>
<item name="android:colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="android:colorAccent">#color/colorAccent</item>
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="android:windowBackground">#drawable/parquet</item>
<item name="android:actionBarStyle">#style/ActionBarStyle.Transparent</item>
</style>
<style name="ActionBarStyle.Transparent" parent="android:Widget.Material.Light.ActionBar">
<item name="android:background">#null</item>
</style>
I am on android lollipop and using the following style as my theme MyNavigationDrawerTheme
in styles v14
<style name="MyNavigationDrawerTheme" parent="MaterialNavigationDrawerTheme.Light">
<item name="actionMenuTextColor">#color/white</item>
</style>
in material drawer theme.xml (mostly irrelevant to this issue)
<style name="MaterialNavigationDrawerTheme.Light" parent="Theme.AppCompat.Light.NoActionBar" >
<item name="drawerType">#integer/DRAWERTYPE_ACCOUNTS</item>
<item name="drawerColor">#fafafa</item>
</style>
I understand that the theme Theme.AppCompat.Light.NoActionBar has black text for the action bar but why isn't it changing when I include the line
<item name="actionMenuTextColor">#color/white</item>
I have been trying to fix this for almost two days now tried so many things (eg here) but nothing works
Any idea
you could try this in styles.xml:
<style name="MyNavigationDrawerTheme" parent="MaterialNavigationDrawerTheme.Light">
<item name="android:actionMenuTextColor">#color/white</item>
<item name="android:actionMenuTextAppearance">#style/TextAppearance.ActionMenu
</item>
</style>
<style name="TextAppearance.ActionMenu">
<item name="android:textColor">#color/white</item>
</style>
ps:
yeah ,sometimes it won't works only by android:actionMenuTextColor ,such as Galaxy S4
just add attr android:actionMenuTextAppearance
In case you are using Toolbar, this is how you do it -
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:textColorPrimary">#android:color/holo_red_dark</item>
<item name="textColorPrimary">#android:color/holo_red_dark</item>
<!-- Customize your theme here. -->
</style>
Should work like a charm :)
I want to change the color of the title bar. I tried this:
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:actionBarStyle">#style/ColorBar</item>
</style>
<style name="ColorBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#color/white</item>
<item name="android:textColor">#color/orange</item>
</style>
But it doesn't work. What is wrong in my code shown above?
EDIT : it's the color of the text i want to change, not the background (it's running for the background)
This should work for all devices, you will need the support library (appcompat_v7)
<style name="Theme" parent="#style/BaseTheme"></style>
<style name="BaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="actionBarStyle">#style/ActionBar</item>
<item name="android:actionBarStyle">#style/ActionBar</item>
</style>
<style name="ActionBar" parent="#style/Widget.AppCompat.Light.ActionBar">
<item name="android:background">#color/orange </item>
<item name="background">#color/orange </item>
<item name="android:titleTextStyle">#style/ActionBar.Text</item>
<item name="titleTextStyle">#style/ActionBar.Text</item>
</style>
<style name="ActionBar.Text" parent="#android:style/TextAppearance.Medium">
<item name="android:textColor">#color/orange</item>
</style>
manifest :
android:theme="#style/Theme"
There may be problem with the android version. You should consider old ones and new ones. Try adding these both lines for different versions.
<item name="android:background">#drawable/your_color</item>
<item name="background">#drawable/your_color</item>
Does changing the parent to parent="#android:style/Widget.Holo.Light.ActionBar.Solid" make a difference?
If not, let me know what happens if you move the
<item name="android:actionBarStyle">#style/ColorBar</item> into the AppBaseTheme style
Try setting all of these:
<item name="android:background">#color/something</item>
<item name="android:backgroundStacked">#color/something</item>
<item name="android:backgroundSplit">#color/something</item>
This is an easy way for settings the color of the actionbar-title by Java
getActionBar().setTitle(Html.fromHtml("<font color=\"#ffffff\">" + "TITLE" + "</font>"));
If you're using a support library, then you can use getSupportActionBar();.
I'm new to all of this but I found it easier to go to Res > Value > colors.xml and from there you can change the "primary color." This changed the title bar to the color I selected.
I tried change color of my actionBar divider , but nothing work. I' using android support library v7 for support old devices and custom style, and i also change all action bar drawable, but nothing happend!
<resources>
<style name="MyTheme" parent="Theme.AppCompat">
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent = "Widget.AppCompat.ActionBar">
<item name="background">#drawable/my_action_bar</item>
</style>
</resources>
And my ide show me strange error in layout , why did i get this error? it's not color value
java.lang.NumberFormatException: Color value '#drawable/abs__ab_transparent_dark_holo' must start with #
Solution: Need to add android namespace if use for api level >= 14 .May be it will be helpful to someone.
It is because the "divider" is an image. It's hardcoded in the Holo theme assets.
Look at platforms/android-19/data/res/drawable-xxhdpi/ab_transparent_dark_holo.9.png
The style is declared here for holo dark.
<style name="Widget.Holo.ActionBar" parent="Widget.ActionBar">
...
<item name="android:background">#android:drawable/ab_transparent_dark_holo</item>
...
</style>
It's a background. You will need to change the color in the image and replace the background of your bar.
It also needs different sizes for different resolutions.
Maybe you should set color directly, change your theme as
<item name="android:divider">#color/dividercolor</item>
Then you should add color dividercolor in you /value/color file,like
<item name="dividercolor"> #0099CC </item>
I hope this will be helpful to you
<style name="CustomTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyTheme.ActionBarStyle</item>
<item name="android:actionBarDivider">#drawable/action_vertical_doted</item>
<item name="android:actionButtonStyle">#style/MyTheme.ActionBar.ActionButton</item>
<item name="android:actionMenuTextColor">#ffffff</item>
<!-- <item name="android:actionMenuTextAppearance">#style/MyTheme.Menu.FontStyle</item> -->
<!-- <item name="android:actionBarSize">50dp</item> -->
</style>
<style name="MyTheme.ActionBarStyle" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:titleTextStyle">#style/MyTheme.ActionBar.TitleTextStyle</item>
<item name="android:background">#drawable/actionbar_bg_shap</item>
<item name="android:displayOptions">none</item>
<item name="android:backgroundSplit">#drawable/actionbar_bg_shap</item>
</style>
<style name="MyTheme.ActionBar.ActionButton" parent="#android:style/Widget.Holo.Light.ActionButton">
<item name="android:background">#drawable/main_button_inactive_tr</item>
</style>