I'm using Android Studio and I have this error during the build of the project:
:app:mergeDebugResources FAILED Error:Execution failed for task
':app:mergeDebugResources'.
Unsupported node 'item' in file C:\Users\Mh2\Desktop\IlMartino2doppiofinal\app\src\main\res\values\styles.xml
I tried to clean and rebuild the project but it seems not to be the solution.
Here there is my styles.xml file:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"/>
<!-- Customize your theme here. -->
<item name="homeAsUpIndicator">#drawable/ic_drawer</item>
<item name="android:homeAsUpIndicator">#drawable/ic_drawer</item>
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">#color/black</item>
<!-- colorPrimaryDark is used for the status bar
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
-->
<!-- colorAccent is used as the default value for colorControlActivated
which is used to tint widgets -->
<!-- You can also set colorControlNormal, colorControlActivated
colorControlHighlight & colorSwitchThumbNormal. -->
<item name="colorControlNormal">#color/purple</item>
<item name="colorControlActivated">#color/red</item>
<item name="colorControlHighlight">#color/darkred</item>
<item name="colorSwitchThumbNormal">#color/darkorange</item>
</resources>
How can I find a solution?
here:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"/>
you closed it with />
You should make it like
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item........
</style>
Related
I've created a project and added 2 buttons in activity_main.xml but they have different colors in layout preview and the actual app. How come?
There are 2 files under themes:
themes.xml:
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="NecklaceShowcase" parent="Theme.MaterialComponents.Light.NoActionBar" >
<!-- Primary brand color. -->
<item name="colorPrimary">#color/purple_500</item>
<item name="colorPrimaryVariant">#color/purple_700</item>
<item name="colorOnPrimary">#color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">#color/teal_200</item>
<item name="colorSecondaryVariant">#color/teal_700</item>
<item name="colorOnSecondary">#color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>
and themes.xml (night)
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="NecklaceShowcase">
<!-- Primary brand color. -->
<item name="colorPrimary">#color/purple_200</item>
<item name="colorPrimaryVariant">#color/purple_700</item>
<item name="colorOnPrimary">#color/black</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">#color/teal_200</item>
<item name="colorSecondaryVariant">#color/teal_200</item>
<item name="colorOnSecondary">#color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>
The layout preview is using the theme you have set in your themes.xml file.
When you run the app the btn2 is switching to red because in your activity_main.xml it is setting its background to: halo_red_light.
I'm unable to tell why the other button is changed to grey this may have been set in your activity class.
You can read more here
I am trying to stylize the TextInputLayout with an outline. But when I try to use #style/Widget.MaterialComponents.TextInputLayout.OutlinedBox in style attribute my app crashes with this exception:
Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
Here is the TextInputLayout theme I want to use OutlinedBox
It was working fine but suddenly this error appeared during development
<style name="LoginTextInputLayoutStyle" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense">
<item name="boxStrokeColor">#color/text_input_box_stroke</item>
</style>
Global App Theme
<!-- Base application No Action bar theme. -->
<style name="AppTheme" 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>
<item name="android:fontFamily">#font/opensans_regular</item>
</style>
As reported in the error:
Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant)
You have to change the app theme to a Material Components Theme like:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- ... -->
</style>
I want to achieve a somewhat orange color for my actionbar. The problem is, I am using an appcompat theme for my app:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
</style>
<style name="menu_labels_style">
<item name="android:background">#drawable/fab_label_background</item>
<item name="android:textColor">#color/white</item>
</style>
</resources>
So the usual way with:
<resources>
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#F39530</item>
</style>
</resources>
(for example), won't work. So how do I change the color of the actionbar in an AppCompat theme?
Use colorPrimary to set the color, as in
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">#color/background_green</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">#color/background_green</item>
<!-- colorAccent is used as the default value for colorControlActivated,
which is used to tint widgets -->
<item name="colorAccent">#color/darkgreen_activeTextColor</item>
<style>
See also this blog post from google devs
AppCompat v21 — Material Design for Pre-Lollipop Devices
i am trying to add Custom background to AppCompat action bar. Here is my 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="Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<!--
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>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:background">#drawable/top_bar_bg</item>
</style>
I am using AppTheme as my Theme. It still shows default dark background. What am i missing here?
In res/values/styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="background">#drawable/actionbar_background</item>
</style>
</resources>
In res/values-v11/styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android: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>
</style>
</resources>
I'm using Android studio and actually I'm styling Action bar.
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar"
parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:background">#color/oranzova</item>
<item name="android:icon">#drawable/ic_launcher.png</item>
</style>
</resources>
I'm still getting error :
Error:(12, 35) No resource found that matches the given name (at 'android:icon' with value '#drawable/ic_launcher.png').
but no matters which resource I'm using. If i use #raw/icon.png i get still same error. I tried to Invalidate Caches/restart but no help.
You don't need a file-extension like *.png on resource-files. So just change your line:
<item name="android:icon">#drawable/ic_launcher.png</item>
to
<item name="android:icon">#drawable/ic_launcher</item>