Hey guys I am new to development for the Android, I have a question for a project I am working on:
Using these styles to style my actionbar:
<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>
I get an error for both styles, they say:
error: Error retrieving parent for item: No resource found that matches the given name '#style/
Theme.Holo.Light.DarkActionBar'.
error: Error retrieving parent for item: No resource found that matches the given name '#style/
Widget.Holo.Light.ActionBar.Solid.Inverse'.
I am putting these in a separate XML file called themes. In my style XML file I have the theme android:Theme.Light
If you could give me a suggestion or whatnot as to what is wrong here I would appreciate it!
David
"#style/Theme.Holo.Light.DarkActionBar"
You are referring to the styles in your values/styles.xml and you do not have the style mentioned in styles.xml. You probable meant to refer to the one in the android style package like #android:style/..
Change to
<resources>
<style name="CustomActionBarTheme" parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#drawable/actionbar_background</item>
</style>
</resources>
Related
How can I change the text color of a context menu's header?
Currently my styles.xml is as follows:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="#android:style/Theme.Material.Light.DarkActionBar">
<!-- 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:contextPopupMenuStyle">#style/ContextMenuStyle</item>
</style>
<style name="ContextMenuStyle"
parent="#android:style/TextAppearance.Material.Widget.PopupMenu">
</style>
<style name="ContextMenuStyle.Header"
parent="#android:style/TextAppearance.Material.Widget.PopupMenu.Header">
<item name="android:textColor">#android:color/black</item>
</style>
</resources>
But gradle gives me lots of errors when building, like:
app/src/main/res/values/styles.xml:16:5-19:13: AAPT: Error retrieving parent for item: No resource found that matches the given name '#android:style/TextAppearance.Material.Widget.PopupMenu.Header'.
I obtained the style name TextAppearance.Material.Widget.PopupMenu.Header from the Android source:
https://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/values/styles_material.xml
What is the proper way to set the context menu's text color in styles.xml?
Sorry for my english. I try change action bar collor. And i have this error:
error: Error retrieving parent for item: No resource found that
matches the given name '#android:style/
Widget.AppCompat.Light.ActionBar.Solid.Inverse'.
I have minSdkVersion = 12
style.xml
<resources xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android">
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
//this is error
<style name="MyActionBar" parent="#android:style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#FF9D21</item>
</style>
</resources>
UPD
I have added appcompat_v7, but its not work
UPD
now style.xml looking that:
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#FF9D21</item>
</style>
in manifest:
android:theme="#style/MyTheme" >
i have error:
03-05 12:45:33.860: E/AndroidRuntime(2006):
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.example.test6/com.example.test6.MainActivity}:
java.lang.IllegalStateException: You need to use a Theme.AppCompat
theme (or descendant) with this activity.
if i change manifest like that:
android:theme="#style/Theme.AppCompat" >
no error but after this no change color action bar
Try #style/Widget.AppCompat.Light.ActionBar.Solid.Inverse instead .
On a side note, the styles.xml file on appcompat_v7 suggests that #style/Widget.AppCompat.Light.ActionBar.Solid.Inverseis deprecated. #android:style/Widget.DeviceDefault.Light.ActionBar.Solid.Inverse is an alternative.
I had this problem in my v21\styles.xml file.
Solution:
parent="Widget.AppCompat.Light.ActionBar.Solid.Inverse"
This works for me
<style name="AppBarStyle" parent="#android:style/Widget.DeviceDefault.Light.ActionBar.Solid.Inverse">
I am trying to change the color of my action bar in android studio. I have already changed the minSDKVersion to 21 so I know that is not the problem. Yet I keep getting the error, I don't know what is going on. Here is my xml:
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Material">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/my_action_bar_color</item>
<item name="android:navigationBarColor">#color/my_action_bar_color</item>
</style>
No resource found that matches the given name: attr 'colorPrimary'.
Use android:colorPrimary. colorPrimary on its own will only work if you are inheriting from Theme.AppCompat.
So, for example, in this sample project, I have:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Apptheme" parent="android:Theme.Material">
<item name="android:colorPrimary">#color/primary</item>
<item name="android:colorPrimaryDark">#color/primary_dark</item>
<item name="android:colorAccent">#color/accent</item>
</style>
</resources>
Unable to resolve "error: Error: No resource found that matches the given name (at 'android:actionMenuTextColor' with value '#color/actionbar_text')." Using eclipse with current SDK. Min for this tutorial app is 14 and target is 19.
Seems like it should be simple but I have not found any answer for this. The logic is in the res/values/themes.xml file.
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style
name="CustomActionBarTheme"
parent="#android:style/Theme.Holo">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarTabTextStyle">#style/MyActionBarTabText</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:actionMenuTextColor">#color/actionbar_text</item>
</style>
<!-- ActionBar styles -->
<style
name="MyActionBar"
parent="#android:style/Widget.Holo.ActionBar">
<item name="android:titleTextStyle">#style/MyActionBarTitleText</item>
</style>
<!-- ActionBar title text -->
<style
name="MyActionBarTitleText"
parent="#android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#color/actionbar_text</item>
</style>
<!-- ActionBar tabs text styles -->
<style
name="MyActionBarTabText"
parent="#android:style/Widget.Holo.ActionBar.TabText">
<item name="android:textColor">#color/actionbar_text</item>
</style>
</resources>
"#color/actionbar_text)" In this line "#color" means that it is referring to a "color.xml" file which should be in "res/velues/" to solve this problem.
You can create your "color.xml" file in following way ,
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="actionbar_text">#ffffff</color>
</resources>
"#ffffff" is hex color code for white color, you may google for more codes.
here is the link for your help Color Codes and Names
Do you have a color defined in your /res/values/colors.xml file that is named "actionbar_text"?
Download the zip file from Action Bar Style Generator. Be sure that the first field in the form is blank (if 'example' is in this field, be sure to delete it). Extract the resulting zip file into your project's res (resources) folder. This will plug in all of your missing style components, and you should be ready to roll :)
I'm using ActionBarSherlock, and want to use a custom background for both the ActionBar and the content view below it. When I try this, the background fills the whole screen, including the actionbar:
<style name="MyTheme" parent="#style/Theme.Sherlock">
<item name="android:windowBackground">#drawable/background</item>
</style>
So, from this answer, I tried to add abBackground to the theme:
<style name="MyTheme" parent="#style/Theme.Sherlock">
<item name="android:windowBackground">#drawable/background</item>
<item name="abBackground">#drawable/bg_button_idle</item>
</style>
However, I get the error
Error: No resource found that matches the given name: attr 'abBackground'.
Why is this, and how can I fix it?
Here's how you can change the actionbar background:
<style name="MyTheme" parent="Theme.Sherlock">
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="Widget.Sherlock.ActionBar">
<item name="background">#drawable/your_custom_drawable</item>
<item name="android:background">#drawable/your_custom_drawable</item>
</style>
//there is no abBackground
<item name="abBackground">#drawable/bg_button_idle</item>
//try
<item name="android:background">#drawable/bg_button_idle</item>
if the project is a library module you shou check the Library module