Error: 'color' attribute should be defined - android-selector

A color selector is defined as following:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true">
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#color/gray" />
</shape>
</item>
<item android:state_focused="true">
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#66666666" />
</shape>
</item>
<item>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#color/translucent_icon_background" />
</shape>
</item>
</selector>
In Android Studio, 'item" is marked red indicating an error as shown by the following screenshot:
The app works fine per tests. I am asking because I am afraid it may not be fine on some devices due to that error. Could anyone shed some light on this error? More specifically, can it be ignored?

I had the same error and I removed it by adding a color attribute with the item tag.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" android:color="#ffffff"> <--**add this**
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#color/gray" />
</shape>
</item>
<item android:state_focused="true" android:color="#ffffff"> **<--add this**
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#66666666" />
</shape>
</item>
<item android:color="#ffffff"> **<--add this**
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#color/translucent_icon_background" />
</shape>
</item>
Good luck.

You need to create the 'selector.xml' in the 'drawable/' folder rather than 'color/' folder.enter image description here

Related

in xslt match decimal with in text and write after it

I have a problem. I think it is simple but I havent found it.
like below code I want to find and match multiplier factor value like "0.05" with "005" in the note value dynamically and take text "AAA" after "_ 005 _"(without spaces) and write it and others too.
I tried to use together both format number and concatenate to "concat(format-number(***))" but failed because of newby about this.
<cbc:Note>40.00 BT</cbc:Note>
<cbc:Note>17_ 2005.00</cbc:Note>
<cbc:Note>11_005_AAA</cbc:Note>
<cbc:Note>11_002_BBB</cbc:Note>
<cbc:Note>11_003_CCC</cbc:Note>
<cbc:InvoicedQuantity unitCode="CS">1.000</cbc:InvoicedQuantity>
<cbc:LineExtensionAmount currencyID="TRY">200.00</cbc:LineExtensionAmount>
<cac:AllowanceCharge>
<cbc:ChargeIndicator>false</cbc:ChargeIndicator>
<cbc:MultiplierFactorNumeric>0.03</cbc:MultiplierFactorNumeric>
<cbc:Amount currencyID="TRY">6.00</cbc:Amount>
<cbc:BaseAmount currencyID="TRY">200.00</cbc:BaseAmount>
</cac:AllowanceCharge>
<cac:AllowanceCharge>
<cbc:ChargeIndicator>false</cbc:ChargeIndicator>
<cbc:MultiplierFactorNumeric>0.05</cbc:MultiplierFactorNumeric>
<cbc:Amount currencyID="TRY">10.00</cbc:Amount>
<cbc:BaseAmount currencyID="TRY">200.00</cbc:BaseAmount>
</cac:AllowanceCharge>
current xslt block
<xsl:for-each select="./cac:AllowanceCharge/cbc:MultiplierFactorNumeric">
<br/>
<xsl:text> %</xsl:text>
<xsl:value-of select="format-number(. * 100, '###.##0,00', 'european')"/>,
</xsl:for-each>
I appreciate if you help me.
It is very difficult to understand your question.
The following minimal example is mostly based on a guess. It formats the MultiplierFactorNumeric value as a 3-digit whole number and uses it as a key to retrieve the corresponding Note value:
XML
<root>
<Note>40.00 BT</Note>
<Note>17_ 2005.00</Note>
<Note>11_005_AAA</Note>
<Note>11_002_BBB</Note>
<Note>11_003_CCC</Note>
<AllowanceCharge>
<MultiplierFactorNumeric>0.03</MultiplierFactorNumeric>
</AllowanceCharge>
<AllowanceCharge>
<MultiplierFactorNumeric>0.05</MultiplierFactorNumeric>
</AllowanceCharge>
</root>
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:key name="note" match="Note" use="substring-before(substring-after(., '_'), '_')" />
<xsl:template match="/root">
<result>
<xsl:for-each select="AllowanceCharge">
<item>
<factor>
<xsl:value-of select="MultiplierFactorNumeric"/>
</factor>
<value>
<xsl:value-of select="substring-after(substring-after(key('note', format-number(100*MultiplierFactorNumeric, '000')), '_'), '_')"/>
</value>
</item>
</xsl:for-each>
</result>
</xsl:template>
</xsl:stylesheet>
Result
<?xml version="1.0" encoding="UTF-8"?>
<result>
<item>
<factor>0.03</factor>
<value>CCC</value>
</item>
<item>
<factor>0.05</factor>
<value>AAA</value>
</item>
</result>

How to change the tab layout theme programmatically?

I have created a custom style for my tab layout in styles.xml file.
styles.xml:
<style name="AppTabLayout" parent="Widget.Design.TabLayout">
<item name="tabMaxWidth">#dimen/tab_max_width</item>
<item name="tabIndicatorColor">?attr/colorAccent</item>
<item name="tabIndicatorHeight">4dp</item>
<item name="tabPaddingStart">6dp</item>
<item name="tabPaddingEnd">6dp</item>
<item name="tabBackground">?attr/selectableItemBackground</item>
<item name="tabTextAppearance">#style/AppTabTextAppearance</item>
<item name="tabSelectedTextColor">#color/range</item>
</style>
<!-- for text -->
<style name="AppTabTextAppearance" parent="TextAppearance.Design.Tab">
<item name="android:textSize">12sp</item>
<item name="android:textColor">#color/orange</item>
<item name="textAllCaps">false</item>
</style>
Apply:
<android.support.design.widget.TabLayout
style="#style/AppTabLayout"
app:tabTextAppearance="#style/AppTabTextAppearance"
android:layout_width="match_parent"
.... />
I used this code for my tablayout.
Everything works fine. But I want to change the style at runtime. I have gone through stackoverflow, but haven't found anything about this. Is it possible ?
styles.xml
<resources>
<attr name="tabLayoutStyle" format="reference" />
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
</style>
<style name="AppTheme.Blue">
<item name="tabLayoutStyle">#style/Blue.TabLayout</item>
</style>
<style name="Blue.TabLayout" parent="Base.Widget.Design.TabLayout">
<item name="tabSelectedTextColor">#color/selected_textBlue</item>
<item name="tabIndicatorColor">#color/accent_blue</item>
<item name="tabBackground">#color/primary_blue</item>
</style>
<style name="AppTheme.Red">
<item name="tabLayoutStyle">#style/Red.TabLayout</item>
</style>
<style name="Red.TabLayout" parent="Base.Widget.Design.TabLayout">
<item name="tabSelectedTextColor">#color/selected_textRed</item>
<item name="tabIndicatorColor">#color/accent_red</item>
<item name="tabBackground">#color/primary_red</item>
</style>
<color name="selected_textBlue">#000055</color>
<color name="accent_blue">#0000ff</color>
<color name="primary_blue">#0099ff</color>
<color name="selected_textRed">#880022</color>
<color name="accent_red">#550000</color>
<color name="primary_red">#ff0000</color>
</resources>
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical">
<android.support.design.widget.TabLayout
style="?attr/tabLayoutStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TabItem
android:text="Tab 1" />
<android.support.design.widget.TabItem
android:text="Tab 2" />
</android.support.design.widget.TabLayout>
<Button
android:id="#+id/mainButton0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Red"
android:onClick="onClick" />
<Button
android:id="#+id/mainButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Blue"
android:onClick="onClick" />
</LinearLayout>
MainActivity.java
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(PreferenceManager.getDefaultSharedPreferences(this)
.getInt("theme", R.style.AppTheme_Blue));
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onClick(android.view.View v) {
switch (v.getId()) {
case R.id.mainButton0:
PreferenceManager.getDefaultSharedPreferences(this)
.edit().putInt("theme",
R.style.AppTheme_Red).commit();
break;
case R.id.mainButton1:
PreferenceManager.getDefaultSharedPreferences(this)
.edit().putInt("theme",
R.style.AppTheme_Blue).commit();
break;
}
recreate();
}
}

Xml output showing blank

I'm new to XML i have made an XML file and an XSL file. After linking the XSL file to the XML file, the output of the XML in the browser goes blank. I could not find the error.
This is my XML:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="cupcake.xsl"?>
<cupcakes>
<item>
<name>Luscious Vanilla</name>
<flavour>Vanilla</flavour>
<colour>Brown</colour>
<energy> 100 cj </energy>
</item>
<item>
<name>Chocolate Hazelnut</name>
<flavour>chocolaty</flavour>
<colour>coffe</colour>
<energy> 100 cj </energy>
<cost> $10 </cost>
</item>
<item>
<name>Risch Red Velvet</name>
<flavour>red velvet</flavour>
<colour>red</colour>
<energy> 100 cj </energy>
<cost> $10 </cost>
</item>
<item>
<name>Classic straberry</name>
<flavour>straberry</flavour>
<colour>pink</colour>
<energy> 100 cj </energy>
<cost> $10 </cost>
</item>
<item>
<name>Lemon Drop</name>
<flavour>lemon</flavour>
<colour>yellow</colour>
<energy> 100 cj </energy>
<cost> $10 </cost>
</item>
</cupcakes>
And this is my XSL:
<?xml version="1.0" encoding="UTF-8"?>
<html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<body style="font-family:Arial;font-size:12pt;background-color:#EEEEEE">
<xsl:for-each select="cupcakes/item">
<div style="background-color:teal;color:white;padding:4px">
<span style="font-weight:bold"><xsl:value-of select="name"/> - </span>
<xsl:value-of select="price"/>
</div>
<div style="margin-left:20px;margin-bottom:1em;font-size:10pt">
<p>
<xsl:value-of select="cost"/>
</p>
</div>
</xsl:for-each>
</body>
</html>

SCORM 1.2 Nested Items In Manifest

I've been trying to create a SCORM 1.2 manifest file that will create multiple SCOs with sub-files but, although there's plenty written about it online, I've been unable to find any actual examples. Essentially, what I want to do is:
SCO1.html
SCO1.1.html
SCO1.2.html
SCO1.3.html
SCO2.html
SCO2.1.html
SCO2.2.html
SCO2.3.html
In the above scenario, if the user was to launch SCO1.2.html, for example, their progress would be recorded against SCO1. I've got the following in my imsmanifest.xml file, but don't know how to restructure it so that each item is not a separate SCO. I've left out the metadata and resources that don't affect this issue:
<organizations default="TOC1">
<organization identifier="TOC1">
<title>Test</title >
<item identifier="I_SCO1" identifierref="SCO1">
<title>SCO1</title>
</item>
<item identifier="I_SCO1.1" identifierref="SCO1.1">
<title>SCO1.1</title>
</item>
<item identifier="I_SCO1.2" identifierref="SCO1.2">
<title>SCO1.2</title>
</item>
<item identifier="I_SCO1.3" identifierref="SCO1.3">
<title>SCO1.3</title>
</item>
<item identifier="I_SCO2" identifierref="SCO2">
<title>SCO2</title>
</item>
<item identifier="I_SCO2.1" identifierref="SCO2.1">
<title>SCO2.1</title>
</item>
<item identifier="I_SCO2.2" identifierref="SCO2.2">
<title>SCO2.2</title>
</item>
<item identifier="I_SCO2.3" identifierref="SCO2.3">
<title>SCO2.3</title>
</item>
</organization>
</organizations>
<resources>
<resource identifier="SCO1" type="webcontent" adlcp:scormtype="sco" href="SCO1.html">
<file href="SCO1.html" />
<dependency identifierref="ALLRESOURCES" />
</resource>
<resource identifier="SCO1.1" type="webcontent" adlcp:scormtype="sco" href="SCO1.1.html">
<file href="SCO1.1.html" />
<dependency identifierref="ALLRESOURCES" />
</resource>
<resource identifier="SCO1.2" type="webcontent" adlcp:scormtype="sco" href="SCO1.2.html">
<file href="SCO1.2.html" />
<dependency identifierref="ALLRESOURCES" />
</resource>
<resource identifier="SCO1.3" type="webcontent" adlcp:scormtype="sco" href="SCO1.3.html">
<file href="SCO1.3.html" />
<dependency identifierref="ALLRESOURCES" />
</resource>
<resource identifier="SCO2" type="webcontent" adlcp:scormtype="sco" href="SCO2.html">
<file href="SCO2.html" />
<dependency identifierref="ALLRESOURCES" />
</resource>
<resource identifier="SCO2.1" type="webcontent" adlcp:scormtype="sco" href="SCO2.1.html">
<file href="SCO2.1.html" />
<dependency identifierref="ALLRESOURCES" />
</resource>
<resource identifier="SCO2.2" type="webcontent" adlcp:scormtype="sco" href="SCO2.2.html">
<file href="SCO2.2.html" />
<dependency identifierref="ALLRESOURCES" />
</resource>
<resource identifier="SCO2.3" type="webcontent" adlcp:scormtype="sco" href="SCO2.3.html">
<file href="SCO2.3.html" />
<dependency identifierref="ALLRESOURCES" />
</resource>
</resources>
Any help would be appreciated.
You'll be looking at something a little closer to this-
<organizations default="ORG-001">
<organization identifier="ORG-001">
<title>Page Progression Sample</title>
<item>
<title>Module 1</title>
<item identifier="ACT-001" identifierref="RES-001">
<title>Name of this page</title>
</item>
<item identifier="ACT-002" identifierref="RES-002">
<title>Name of this page</title>
</item>
<item identifier="ACT-003" identifierref="RES-003">
<title>Name of this page</title>
</item>
<item identifier="ACT-004" identifierref="RES-004">
<title>Name of this page</title>
</item>
</item>
<item>
<title>Module 2</title>
<item identifier="ACT-005" identifierref="RES-005">
<title>Name of this page</title>
</item>
<item identifier="ACT-006" identifierref="RES-006">
<title>Name of this page</title>
</item>
<item identifier="ACT-007" identifierref="RES-007">
<title>Name of this page</title>
</item>
<item identifier="ACT-008" identifierref="RES-008">
<title>Name of this page</title>
</item>
</item>
</organization>
But you could try nesting 2, 3, 4 within 1 to see if that works. I don't have the specification in front of me right now.
In your example -
<item identifier="I_SCO1" identifierref="SCO1">
<title>SCO1</title>
<!-- PUT YOUR NEXT SCO (page) HERE-->
</item> <!-- Close tag of SCO1 -->

XmlPad problems with XPath for finding duplicate nodes

[EDIT] It seems that there is a bug in the XML Editor I'm using (XmlPad) that prevents the Xpath query from returning the correct results. I've tested the same query using two online tools (http://www.zrinity.com/xml/xpath/xpath.cfm and http://www.futurelab.ch/xmlkurs/xpath.en.html) and it seems to work. biziclop also commented that the query works correctly in Oxygen.
I've got this structure:
<?xml version="1.0" encoding="utf-8"?>
<root>
<itemlist>
<item>
<code>0001.0.00</code>
<category>709</category>
</item>
<item>
<code>0001.0.00</code>
<category>709</category>
</item>
<item>
<code>0002.0.00</code>
<category>708</category>
</item>
</itemlist>
<itemlist>
<item>
<code>0016.0.00</code>
<category>52</category>
</item>
<item>
<code>0016.0.00</code>
<category>52</category>
</item>
<item>
<code>0016.0.00</code>
<category>51</category>
</item>
<item>
<code>0016.0.00</code>
<category>50</category>
</item>
<item>
<code>0869.0.00</code>
<category>52</category>
</item>
<item>
<code>0869.0.00</code>
<category>51</category>
</item>
<item>
<code>0869.0.00</code>
<category>50</category>
</item>
</itemlist>
</root>
I want find all items where the previous item has the same category.
This Xpath query:
//item[category = preceding-sibling::item[1]/category]
returns the following nodes:
<item>
<code>0001.0.00</code>
<category>709</category>
</item>
<item>
<code>0016.0.00</code>
<category>52</category>
</item>
<item>
<code>0869.0.00</code>
<category>52</category>
</item>
The last item node in the result set is incorrect, because the value of the previous item's category in the input is not 52 so it should not be returned.
Is there an Xpath query that will return the results I want?
This XPath is absolutely correct. I've tested it with Saxon XSLT processor as follows:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:copy-of select="//item[category
= preceding-sibling::item[1]/category]"/>
</xsl:template>
</xsl:stylesheet>
With results:
<item>
<code>0001.0.00</code>
<category>709</category>
</item>
<item>
<code>0016.0.00</code>
<category>52</category>
</item>
You might want also try alternatives:
//item[category = ./preceding-sibling::item[1]/category]
/root/itemlist/item[category = ./preceding-sibling::item[1]/category]