Error:(144) Attribute "srcCompat" has already been defined - java

I've coded an application which can post tweets and you can see user timelines and search timelines with it. I did that with the TwitterAPI and fabric.io. And if I want to generate an APK file or sync the Gradle file, I get these errors:
C:\Users\Alexander\AndroidStudioProjects\FacebookPlus\app\build\intermediates\res\merged\debug\values\values.xml
Error:(140) Attribute "srcCompat" has already been defined
Error:Execution failed for task ':app:processDebugResources'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Users\Alexander\AppData\Local\Android\sdk1\build-tools\23.0.2\aapt.exe'' finished with non-zero exit value 1

I had the same problem but I found a workable solution. Here's the link. Hopefully it sorts you out...

app:srcCompat is an xml attribute usually applied to views like ImageView.
Maybe you declared that attribute twice in the same view.

Answer for Alan_UK's request - I cant post the full content because it is too long. I only post the content which includes the dual attributes
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:ns1="http://schemas.android.com/tools">
<attr format="reference" name="backgroundCompat"/>
<attr format="reference|color" name="dgts__accentColor"/>
<attr format="reference" name="dgts__logoDrawable"/>
<attr format="reference" name="drawerArrowStyle"/>
<attr format="dimension" name="height"/>
<attr format="boolean" name="isInScrollContainer"/>
<attr format="boolean" name="isLightTheme"/>
<attr format="reference" name="srcCompat"/>
<attr format="string" name="title"/>
<attr format="reference" name="tw__twitter_logo"/>
<bool name="abc_action_bar_embed_tabs">true</bool>
<bool name="abc_action_bar_embed_tabs_pre_jb">false</bool>
<bool name="abc_action_bar_expanded_action_views_exclusive">true</bool>
<bool name="abc_allow_stacked_button_bar">true</bool>
<bool name="abc_config_actionMenuItemAllCaps">true</bool>
<bool name="abc_config_allowActionMenuItemTextWithIcon">false</bool>
<bool name="abc_config_closeDialogWhenTouchOutside">true</bool>
<bool name="abc_config_showMenuShortcutsWhenKeyboardPresent">false</bool>
<color name="abc_input_method_navigation_guard">#android:color/black</color>
<color name="abc_search_url_text_normal">#7fa87f</color>
<color name="abc_search_url_text_pressed">#android:color/black</color>
<color name="abc_search_url_text_selected">#android:color/black</color>
<color name="accent_material_dark">#color/material_deep_teal_200</color>
<color name="accent_material_light">#color/material_deep_teal_500</color>
<color name="background_floating_material_dark">#color/material_grey_800</color>
<color name="background_floating_material_light">#android:color/white</color>
<color name="background_material_dark">#color/material_grey_850</color>
<color name="background_material_light">#color/material_grey_50</color>
<color name="bright_foreground_disabled_material_dark">#80ffffff</color>
<color name="bright_foreground_disabled_material_light">#80000000</color>
<color name="bright_foreground_inverse_material_dark">#color/bright_foreground_material_light</color>
<color name="bright_foreground_inverse_material_light">#color/bright_foreground_material_dark</color>
<color name="bright_foreground_material_dark">#android:color/white</color>
<color name="bright_foreground_material_light">#android:color/black</color>
<color name="button_material_dark">#ff5a595b</color>
<color name="button_material_light">#ffd6d7d7</color>
<color name="colorAccent">#e99224</color>
<color name="colorAccentDark">#004676</color>
<color name="colorPrimary">#25c7ac</color>
<color name="colorPrimaryDark">#1d9f8a</color>
<color name="colorfb">#32588e</color>
<color name="design_fab_shadow_end_color">#android:color/transparent</color>
<color name="design_fab_shadow_mid_color">#14000000</color>
<color name="design_fab_shadow_start_color">#44000000</color>
<color name="design_fab_stroke_end_inner_color">#0A000000</color>
<color name="design_fab_stroke_end_outer_color">#0F000000</color>
<color name="design_fab_stroke_top_inner_color">#1AFFFFFF</color>
<color name="design_fab_stroke_top_outer_color">#2EFFFFFF</color>
<color name="design_snackbar_background_color">#323232</color>
<color name="design_textinput_error_color_dark">#FFFF6E6E</color>
<color name="design_textinput_error_color_light">#FFD50000</color>
<color name="dgts__default_accent">#5baaf4</color>
<color name="dgts__default_logo_name">#56626d</color>
<color name="dgts__purple">#744eaa</color>
<color name="dgts__purple_pressed">#553788</color>
<color name="dgts__text_dark">#ff030303</color>
<color name="dgts__text_light">#ffffff</color>
<color name="dim_foreground_disabled_material_dark">#80bebebe</color>
<color name="dim_foreground_disabled_material_light">#80323232</color>
<color name="dim_foreground_material_dark">#ffbebebe</color>
<color name="dim_foreground_material_light">#ff323232</color>
<color name="disabled">#d1d1d1</color>
<color name="error">#ff2424</color>
<color name="foreground_material_dark">#android:color/white</color>
<color name="foreground_material_light">#android:color/black</color>
<color name="grey">#9e9e9e</color>
<color name="highlighted_text_material_dark">#6680cbc4</color>
<color name="highlighted_text_material_light">#66009688</color>
<color name="hint_foreground_material_dark">#color/bright_foreground_disabled_material_dark</color>
<color name="hint_foreground_material_light">#color/bright_foreground_disabled_material_light</color>
<color name="material_blue_grey_800">#ff37474f</color>
<color name="material_blue_grey_900">#ff263238</color>
<color name="material_blue_grey_950">#ff21272b</color>
<color name="material_deep_teal_200">#ff80cbc4</color>
<color name="material_deep_teal_500">#ff009688</color>
<color name="material_grey_100">#fff5f5f5</color>
<color name="material_grey_300">#ffe0e0e0</color>
<color name="material_grey_50">#fffafafa</color>
<color name="material_grey_600">#ff757575</color>
<color name="material_grey_800">#ff424242</color>
<color name="material_grey_850">#ff303030</color>
<color name="material_grey_900">#ff212121</color>
<color name="primary_dark_material_dark">#android:color/black</color>
<color name="primary_dark_material_light">#color/material_grey_600</color>
<color name="primary_material_dark">#color/material_grey_900</color>
<color name="primary_material_light">#color/material_grey_100</color>
<color name="primary_text_default_material_dark">#ffffffff</color>
<color name="primary_text_default_material_light">#de000000</color>
<color name="primary_text_disabled_material_dark">#4Dffffff</color>
<color name="primary_text_disabled_material_light">#39000000</color>
<color name="ripple_material_dark">#33ffffff</color>
<color name="ripple_material_light">#1f000000</color>
<color name="secondary_text_default_material_dark">#b3ffffff</color>
<color name="secondary_text_default_material_light">#8a000000</color>
<color name="secondary_text_disabled_material_dark">#36ffffff</color>
<color name="secondary_text_disabled_material_light">#24000000</color>
<color name="subtitle">#96ffffff</color>
<color name="sv_bgcolor">#d2000000</color>
<color name="switch_thumb_disabled_material_dark">#ff616161</color>
<color name="switch_thumb_disabled_material_light">#ffbdbdbd</color>
<color name="switch_thumb_normal_material_dark">#ffbdbdbd</color>
<color name="switch_thumb_normal_material_light">#fff1f1f1</color>
<color name="trans">#7cffffff</color>
<color name="tt_accent">#0099ff</color>
<color name="tt_accentdark">#0084dc</color>
<color name="tw__blue_default">#FF5BAAF4</color>
<color name="tw__blue_pressed">#FF4186C8</color>
<color name="tw__blue_pressed_light">#ffe1e8ed</color>
<color name="tw__composer_black">#ff292f33</color>
<color name="tw__composer_blue">#ff1da1f2</color>
<color name="tw__composer_blue_text">#ff1b95e0</color>
<color name="tw__composer_deep_gray">#ff8899A6</color>
<color name="tw__composer_light_gray">#ffccd6dd</color>
<color name="tw__composer_red">#ffe81c4f</color>
<color name="tw__composer_white">#ffffffff</color>
<color name="tw__light_gray">#ccd6dd</color>
<color name="tw__medium_gray">#8899a6</color>
<color name="tw__seekbar_thumb_inner_color">#ffffffff</color>
<color name="tw__seekbar_thumb_outer_color">#4dffffff</color>
<color name="tw__solid_white">#FFFFFFFF</color>
<color name="tw__transparent">#00000000</color>
<color name="tw__tweet_action_color">#55acee</color>
<color name="tw__tweet_action_dark_highlight_color">#667580</color>
<color name="tw__tweet_action_light_highlight_color">#ebeef0</color>
<color name="tw__tweet_dark_container_bg_color">#d9000000</color>
<color name="tw__tweet_dark_primary_text_color">#e1ffffff</color>
<color name="tw__tweet_light_container_bg_color">#ffffff</color>
<color name="tw__tweet_light_primary_text_color">#292f33</color>
<declare-styleable name="ActionBar"><attr name="navigationMode"><enum name="normal" value="0"/><enum name="listMode" value="1"/><enum name="tabMode" value="2"/></attr><attr name="displayOptions"><flag name="none" value="0"/><flag name="useLogo" value="0x1"/><flag name="showHome" value="0x2"/><flag name="homeAsUp" value="0x4"/><flag name="showTitle" value="0x8"/><flag name="showCustom" value="0x10"/><flag name="disableHome" value="0x20"/></attr><attr name="title"/><attr format="string" name="subtitle"/><attr format="reference" name="titleTextStyle"/><attr format="reference" name="subtitleTextStyle"/><attr format="reference" name="icon"/><attr format="reference" name="logo"/><attr format="reference" name="divider"/><attr format="reference" name="background"/><attr format="reference|color" name="backgroundStacked"/><attr format="reference|color" name="backgroundSplit"/><attr format="reference" name="customNavigationLayout"/><attr name="height"/><attr format="reference" name="homeLayout"/><attr format="reference" name="progressBarStyle"/><attr format="reference" name="indeterminateProgressStyle"/><attr format="dimension" name="progressBarPadding"/><attr name="homeAsUpIndicator"/><attr format="dimension" name="itemPadding"/><attr format="boolean" name="hideOnContentScroll"/><attr format="dimension" name="contentInsetStart"/><attr format="dimension" name="contentInsetEnd"/><attr format="dimension" name="contentInsetLeft"/><attr format="dimension" name="contentInsetRight"/><attr format="dimension" name="elevation"/><attr format="reference" name="popupTheme"/></declare-styleable>
<declare-styleable name="ActionBarLayout"><attr name="android:layout_gravity"/></declare-styleable>
<declare-styleable name="ActionMenuItemView"><attr name="android:minWidth"/></declare-styleable>
<declare-styleable name="ActionMenuView"/>
<declare-styleable name="ActionMode"><attr name="titleTextStyle"/><attr name="subtitleTextStyle"/><attr name="background"/><attr name="backgroundSplit"/><attr name="height"/><attr format="reference" name="closeItemLayout"/></declare-styleable>
<declare-styleable name="ActivityChooserView"><attr format="string" name="initialActivityCount"/><attr format="reference" name="expandActivityOverflowButtonDrawable"/></declare-styleable>
<declare-styleable name="AlertDialog"><attr name="android:layout"/><attr format="reference" name="buttonPanelSideLayout"/><attr format="reference" name="listLayout"/><attr format="reference" name="multiChoiceItemLayout"/><attr format="reference" name="singleChoiceItemLayout"/><attr format="reference" name="listItemLayout"/></declare-styleable>
<declare-styleable name="AppBarLayout"><attr name="elevation"/><attr name="android:background"/><attr format="boolean" name="expanded"/></declare-styleable>
<declare-styleable name="AppBarLayout_LayoutParams"><attr name="layout_scrollFlags"><flag name="scroll" value="0x1"/><flag name="exitUntilCollapsed" value="0x2"/><flag name="enterAlways" value="0x4"/><flag name="enterAlwaysCollapsed" value="0x8"/><flag name="snap" value="0x10"/></attr><attr format="reference" name="layout_scrollInterpolator"/></declare-styleable>
<declare-styleable name="AppCompatImageView"><attr name="android:src"/><attr format="reference" name="srcCompat"/></declare-styleable>

I had this issue as well.
In my case, the problem was that the support libraries in my gradle file's dependency section should all be the same version.
More info here:
Gradle error "Attribute "xxx" has already been defined" in Android Studio

Related

I can't get my color primary to match the buttons on my screen even though they are the same HEX color in Android Studio

I can't get my colors in my app to line up, even though they supposedly are the same hex code. What I did is I went into Sketch (where I exported and made the buttons) and used the program to get hex code, but as you can see from the picture (below that is not the same color.
https://imgur.com/a/pfcLgOm
Here is my code from my colors file and styles file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name= "color1"> #5AD7DB</color>
<color name= "color2"> #D53D96</color>
<color name= "color3"> #F27E33</color>
</resources>
<resources>
Here is my styles file
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/color1</item>
<item name="colorPrimaryDark">#color/color1</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="MyCustomHelpshiftTheme"
parent="Helpshift.Theme.Light.DarkActionBar">
<item name="colorAccent">#color/color2</item>
<item name="colorPrimary">#color/color1</item>
<item name="colorPrimaryDark">#color/color1</item>
</style>
<style name="Helpshift.Theme.Base" parent="MyCustomHelpshiftTheme"/>
</resources>
Try the below code in your colors.xml file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="color1">#5AD7DB</color>
<color name="color2">#D53D96</color>
<color name="color3">#F27E33</color>
</resources>
Spaces removed where unnecessary..

Customizing JTextField in Synth

I need to change the text color in a JTextField when it gets focus, but it looks like just the state SELECTED works.
<style id="textfield">
<state value="SELECTED">
<color value="#87A0DC" type="TEXT_BACKGROUND"/>
<color value="#000000" type="TEXT_FOREGROUND"/>
</state>
<state value="FOCUSED">
<color value="#000000" type="TEXT_BACKGROUND"/>
<color value="#87A0DC" type="TEXT_FOREGROUND"/>
</state>
</style>
I already have tried with BACKGROUND and FOREGROUND either, but nothing has changed.
If anyone can help, Please.

TypedArray getColor always returns defValue

In my XML element I try to pass through colors from the colors.xml resource file. the getColor function always returns the defValue, even though it should return the colors given in the colors.xml.
code
TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.accordion);
final int col_pressed = a.getColor(R.styleable.accordion_buttonColorPressed, Color.BLACK);
final int col_unpressed = a.getColor(R.styleable.accordion_buttonColorPressed, Color.YELLOW);
btn.setBackgroundColor(col_unpressed);
main XML
<mika.actual.AccordionWidget
xmlns:accordion="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
accordion:text_color="#color/text_color"
accordion:buttonColorPressed="#color/button_pressed"
accordion:buttonColorUnpressed="#color/button_not_pressed"
android:background="#FFFFFFFF"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"> ... </mika.actual.AccordionWidget>
colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="text_color">#FFFFFF</color>
<color name="button_pressed">#666666</color>
<color name="button_not_pressed">#BBBBBB</color>
</resources>
attrs.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="accordion">
<attr name="text_color" format="color"/>
<attr name="buttonColorPressed" format="color"/>
<attr name="buttonColorUnpressed" format="color"/>
</declare-styleable>
</resources>
It's an old thread but no one respond. I will, so viewers can have an answer
I think you just have to change all your accordion: to app: like this
app:text_color="#color/text_color"
app:buttonColorPressed="#color/button_pressed"
app:buttonColorUnpressed="#color/button_not_pressed"

Error: The markup in the document following the root element must be well-formed

i'm new to Android programming, and I have an error,can anybody help me and explain why i have the Error:The markup in the document following the root element must be well-formed? Here is my code. Thank you very much
<color name="puzzle_background">#ffe6f0ff </color>
<color name="puzzle_hilite">#ffffffff</color>
<color name="puzzle_light">#64c6d4ef</color>
<color name="puzzle_dark">#6456648f</color>
<color name="puzzle_foreground">#ff000000</color>
<color name="puzzle_hint_0">#64ff0000</color>
<color name="puzzle_hint_1">#6400ff80</color>
<color name="puzzle_hint_2">#2000ff80</color>
<color name="puzzle_selected">#64ff8000</color>
In XML documents only one element can be at the top level.
Wikipedia: Root element
Wrap your colors into something like :
<colors>
<color name="puzzle_background">#ffe6f0ff </color>
<color name="puzzle_hilite">#ffffffff</color>
<color name="puzzle_light">#64c6d4ef</color>
<color name="puzzle_dark">#6456648f</color>
<color name="puzzle_foreground">#ff000000</color>
<color name="puzzle_hint_0">#64ff0000</color>
<color name="puzzle_hint_1">#6400ff80</color>
<color name="puzzle_hint_2">#2000ff80</color>
<color name="puzzle_selected">#64ff8000</color>
</colors>

How do I use my own colors in android XML

I have an XML file I created in the res/value folder and try to reference it by writing
android:background="#colors/red"
and it does not work.
I also tried placing this file in the drawable folder but to no avail.
Refer to color resources with #color/name, not #colors/name.
For example, in res/values/whatever.xml:
<color name="your_color_name">#12345678</color>
Then in a layout xml:
android:background="#color/your_color_name"
Your color res file has to be under res/values/ (You may add it to a qualifier res/values folder though)
Add the color in this format:
<resources>
<color name="white">#ffffff</color>
</resources>
Refer to it using #color/white.
You can declare a color in your color.xml file like below,
<color name="aqua_blue">#6495ED</color>
And then use it below,
android:background="#color/aqua_blue"
easy way
android:background="#8EE8B5"
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="white">#FFFFFF</color>
<color name="yellow">#FFFF00</color>
<color name="fuchsia">#FF00FF</color>
<color name="red">#FF0000</color>
<color name="silver">#C0C0C0</color>
<color name="gray">#808080</color>
<color name="olive">#808000</color>
<color name="purple">#800080</color>
<color name="maroon">#800000</color>
<color name="aqua">#00FFFF</color>
<color name="lime">#00FF00</color>
<color name="teal">#008080</color>
<color name="green">#008000</color>
<color name="blue">#0000FF</color>
<color name="navy">#000080</color>
<color name="black">#000000</color>
</resources>
make one xml named colors.xml in res and add color names and codes as you want custum

Categories

Resources