Hi I’m new to the whole xml type stuff. I’ve built a ROM called Sourcery for the D1 and I’m looking to write an xml that I want to point at from the drawable.xml in the values folder in the framework-res.apk that part is easy I already have it pointed at an xml I named newbackgrounds.xml and I’ve created it in the values folder.
I want to use it for backgrounds and my idea is to have a selector where it sets an image as a background but if the image is not there to have it be black (#ffffffff). The image is kept in the drawable folder of the framework-res.apk and is named background_dark.jpg
Something kind of like this (again i’m new so pardon any errors here this is just my basic idea)
<?xml version="1.0" encoding="UTF-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item "@drawable/background_dark.jpg"="true"
android:screen_background_dark="@drawable/background_dark.jpg" />
<item "@drawable/background_dark.jpg"="false"
android:screen_background_dark="#ffffffff" />
</selector>
That however didn’t work so what changes need to be made?
Thank you for any help or alternatives it is much appreciated
Your XML is not valid XML, this isn’t what selectors are for, and Android’s resource system does not work this way. 🙂
XML attributes are declared as
namespace:attributeName="value". You cannot use a string in place of an attribute name.Selectors choose a drawable based on predefined states, such as pressed, focused, window focused, enabled, etc. They’re meant to choose at runtime from a set of drawables known at build time. You’re trying to use them to detect whether or not a resource exists, which doesn’t make sense within the Android resource system.
Drawable resource IDs are generated by aapt from resources that exist on the filesystem as image files or XML. If an XML resource references
"@drawable/background_dark"and it doesn’t exist, aapt will fail to build your resources entirely. It’s the same as if you tried to read a variable in Java before declaring it. The file existing is the declaration step.