Android: Custom Action Bar Theme Error - (No Resource Found that Matches . . .) - android

I am working with Android in Eclipse.
So I'm trying to implement a custom theme, and I keep getting this error from my manifest file:
error: Error: No resource found that matches the given name (at 'theme' with value
'#android:style/CustomActionBarTheme').
Ideas? Thanks!
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myfirstapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/CustomActionBarTheme" >
<activity
android:name="com.example.myfirstapp.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- A child of the main activity -->
<activity
android:name="com.example.myfirstapp.DisplayMessageActivity"
android:label="#string/title_activity_display_message"
android:parentActivityName="com.example.myfirstapp.MainActivity" >
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.myfirstapp.MainActivity" />
</activity>
</application>
</manifest>
Themes.xml (Custom theme)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#android:style/Theme.Holo">
<item name="android:windowActionBarOverlay">true</item>
<item name="android:actionBarTabTextStyle">#style/MyActionBarTabText</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>
Styles.xml
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="#android:Theme.Holo.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.
-->
</style>
</resources>

You're referencing the system's resources when you use #android:.... Instead use #style/CustomActionBarTheme.

You need to use
android:theme="#style/CustomActionBarTheme
You are referring to the style in your themes.xml.
There is not resource with the name #android:style/CustomActionBarTheme

Related

Actionbar does not show up in devices, but in emulator does

I have been developing an app and I was using an emulator as tester. When the app was finished I tested it in an Android 5 and also 4 but the Actionbar just won't show up. The platform of the emulator is 5.1.1 as the first phone where I tested it. The only thing that came into my mind is the manifest file that could contain something wrong, here it is:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.flexenergy.swapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="22" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/myActionBarTheme" >
<activity
android:name="com.flexenergy.swapp.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Another thing, I have a drawable listview menu on the left that should appear by pressing on the actionbar (which is not shown) but it does come up if I slide a finger from left to right.
The only styles.xml is the following (and I place it in values-v22, values-v11, etc):
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!--theme applied to the application or activity-->
<style name="myActionbarTheme" parent="android:Theme.Holo">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarTabTextStyle">#style/MyActionBarTabText</item>
<item name="android:actionMenuTextColor">#color/lightBlue</item>
</style>
<!-- actionBar styles -->
<style name="MyActionBar" parent="android:Widget.Holo.ActionBar">
<item name="android:titleTextStyle">#style/MyActionBarTitleText</item>
</style>
<!-- actionBar title text -->
<style name="MyActionBarTitleText" parent="android:TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#color/lightBlue</item>
<item name="android:textSize">20sp</item>
</style>
<!-- actionBar tabs text styles -->
<style name="MyActionBarTabText" parent="android:Widget.Holo.ActionBar.TabText">
<item name="android:textColor">#color/lightBlue</item>
</style>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.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. -->
</style>
</resources>

styling action bar use a Theme.AppCompat

I am following the android training , in styling the Action bar.
I am facing error because of android:theme=#style/MyActionBar.
I want to know how to style the action bar.
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/MyActionBar" >
IllegalStateException: You need to use a Theme.AppCompat theme with
this activity
I thought the error from :
<style name="CustomActionBarTheme"
parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
so I modify it to
<style name="CustomActionBarTheme"
parent="#android:style/Theme.AppCompat.Light ">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
I had the following error :
error: Error retrieving parent for item: No resource found that
matches the given name '#android:style/Theme.AppCompat.Light '.
I created a new file as the training explained
res/values/themes.xml
<?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:actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#aaaaaa</item>
</style>
</resources>
And here is the manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.helloworld"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/MyActionBar" >
<activity
android:name="com.example.helloworld.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.helloworld.DisplayMessageActivity"
android:label="#string/title_activity_display_message"
android:parentActivityName="com.example.Helloworld.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.Helloworld.MyActivity" />
</activity>
</application>
</manifest>
edit your style as follows:
<style name="CustomActionBarTheme"
parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#drawable/actionbar_background</item>
<!-- Support library compatibility -->
<item name="background">#drawable/actionbar_background</item>
</style>
for support library you have to use
name="background">#drawable/actionbar_background</item>
instead of
name="android:background">#drawable/actionbar_background</item>
and then use this theme in your manifest...
before use don't forget to add support:appcompact dependencies in build.gradle if you are using Android Studio...
thanks...
appcompat v7 libary has two kinds of files. One is jar, the other is reses like string.xml styles.xml. You question implies that you didn't import reses of appcompat library. So, import the project of .../Android-SDK/sdk/extras/android/support/v7/appcompat into your Eclipse, and then add it as a libary project of your main project.
I think you have not added a reference of appcompat lib in your project. Add the reference of it to your project and check
https://developer.android.com/tools/support-library/setup.html

Cant set Android Actionbar Background correctly

The Problem
When im setting the ActionBar Background Color the Bar looks like this:
i cant upload Images here so here is the File:
Android ActionBar Problem
My values/styles File
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<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">
<item name="actionBarStyle">#style/ActionBarTheme</item>
</style>
<!-- Action Bar theme -->
<style name="ActionBarTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:background">#drawable/actionbar</item>
<item name="background">#drawable/actionbar</item>
</style>
<style name="FullscreenTheme" parent="android:style/Theme.NoTitleBar.Fullscreen">
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowBackground">#null</item>
<item name="metaButtonBarStyle">#style/ButtonBar</item>
<item name="metaButtonBarButtonStyle">#style/ButtonBarButton</item>
</style>
<style name="ButtonBar">
<item name="android:paddingLeft">2dp</item>
<item name="android:paddingTop">5dp</item>
<item name="android:paddingRight">2dp</item>
<item name="android:paddingBottom">0dp</item>
<item name="android:background">#android:drawable/bottom_bar</item>
</style>
<style name="ButtonBarButton" />
</resources>
My Manifest File
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.application"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/symbol"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.application.Main"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#style/FullscreenTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.application.Settings"
android:parentActivityName="com.application.Main"
android:screenOrientation="portrait"
android:theme="#style/ActionBarTheme">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.application.Main" />
</activity>
<activity
android:name="com.application.DateList"
android:configChanges="orientation|keyboardHidden|screenSize"
android:screenOrientation="portrait"
android:theme="#style/FullscreenTheme" >
</activity>
</application>
</manifest>
I also try this but the same happened
ColorDrawable draw = new ColorDrawable(R.color.grey);
getSupportActionBar().setBackgroundDrawable(draw);
My Color Drawable
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:color="#color/grey" />
</shape>
getSupportActionBar().setBackgroundDrawable(draw);
should be, in your case
getSupportActionBar().setBackgroundDrawable(getResources.getDrawable(R.drawable.your_drawable_name);
The Constructor of ColorDrawable takes the int that represent the color, not the id of the color. Use instenad
ColorDrawable draw = new ColorDrawable(getResources().getColor(R.color.grey));
Edit:
about the style.xml, you need both the item with and without the android prefix:
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:actionBarStyle">#style/ActionBarTheme</item>
<item name="actionBarStyle">#style/ActionBarTheme</item>
</style>
Lint is probably going to complain about it, because of the minSDK value. if it does you can add tools:ignore="NewApi" to the item with the android: prefix. For instance:
<item name="android:actionBarStyle" tools:ignore="NewApi">#style/ActionBarTheme</item>

Android: Error trying to change the background of an actionbar

I am trying to do change the background color of the action bar.
I am following tutorial from this site:
http://developer.android.com/training/basics/actionbar/styling.html
Chapter on Styling the action bar
I receive an error which I can't work out the origin of.
The error is on this line of code
Android Manifest.xml
android:theme="#style/CustomActionBarTheme"
error: Error: No resource found that matches the given name (at 'theme' with value '#style/CustomActionBarTheme').
Could anybody explain why this line throws an error?
Code:
Android Manifest.xml
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/CustomActionBarTheme"
android:uiOptions="splitActionBarWhenNarrow" >
<activity
android:name="com.example.myfirstapp2.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.myfirstapp2.DisplayMessageActivity"
android:label="#string/title_activity_display_message"
android:parentActivityName="com.example.myfirstapp.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.myfirstapp.MainActivity" />
</activity>
</application>
</manifest>
Code: themes.xml
<?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>
code: styles.xml
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.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. -->
</style>
</resources>

After applying custom theme Action bar dosen't show up

I have an application using action bar
styles.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.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. -->
</style>
<color name="custom_theme_color">#ffa900</color>
<style name="CustomTheme" parent="android:Theme.Light">
<item name="android:windowBackground">#color/custom_theme_color</item>
<item name="android:colorBackground">#color/custom_theme_color</item>
</style>
</resources>
manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.actionbar"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/CustomTheme" >
<activity
android:name="com.example.actionbar.ActionBarActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
My Question is that initially by default it was using Theme.Light and action bar is displayed but when I have customized a theme using parent as Theme.Light it dosen't work but if I use parent as Theme.Holo then it works for custom theme. Anyone any Idea.
Here is what I have done. It is working perfectly for me. In Res->value->style
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomTheme"
parent="#style/Theme.Light">
<item android:name="actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style android:name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item android:name="background">#drawable/actionbar_background</item>
</style>
</resources>
Then in drawable folder(create one if you don't have it),create a new xml actionbar_background and paste the below code in it.
<?xml version="1.0" encoding="utf-8"?>
<bitmap android:tileMode="repeat"
android:src="#drawable/ab_texture_tile_example"
xmlns:android="http://schemas.android.com/apk/res/android"/>
Then you place your custom colour in the other drawable folders. Here ab_texture_title_example is my background colour used.

Categories

Resources