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>
Related
i define two theme in styles.xml
AppTheme1 and AppTheme2:
<resources>
<!-- Base application theme. -->
<style name="AppTheme1" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme2" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#00ff00</item>
<item name="colorPrimaryDark">#ff00ff</item>
<item name="colorAccent">#0000ff</item>
</style>
</resources>
when i change theme in application tag inside AndroidManifest.xml
my app theme doesn't any change and the app only use colors.xml and not styles.xml.
for example my manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.maneshtsoft.blackdictionary">
<application
android:allowBackup="true"
android:icon="#mipmap/favicondark"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme2">
<!-- OR AppTheme1 does not matter -->
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
just say that i use toolbar and AppCompactActivity maybe help to answer.
thanks.
The problem may be the cache of InstantRun.
Did you try "Clean & Rerun"? If you use AndroidStudio 2.1 or higher, Select Menu -> Run -> Clean & Rerun.
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>
I have a problem when starting an android project and choose the Holo light, should create a project with the action bar in white color. But I get the action bar in black (and sub menu too).
However if I open a submenu with the menu button instead that from the action bar, on the left bottom, the submenu appears with the style of the Light theme.
Why I get this strange problem?
This is the 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="9"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.actionbar.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>
and this is the style.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="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. -->
</style>
</resources>
I think you forgot the #style/ property as follows:
<style name="AppBaseTheme" parent="#style/Theme.AppCompat.Light">
Update from comments below: make sure that style.xml in res/values-v14/ as the same theme as the above snippnet code.
Let me know if this helps.
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
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.