@drawable/header

How to create your own resource names?

Can I use resource names in themes.xml? For instance:

<item name="headerBackground">@drawable/header</item>

This example is headerBackgroundnot a valid resource ( No resource found that matches the given name...says Eclipse).

Where should I create / declare these resources? It is a bad idea?

+3
source share
1 answer

Of course you can use your own names, otherwise you would be stuck with Android features by default .. :)

Declare names with names by placing a file with that name in a directory res/drawable.


Updated, actual answer:

You need to declare the styleable attribute in res/values/attrs.xml(the actual file name does not matter, but this seems like a convention):

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <declare-styleable name="MyCustomView">
    <attr name="headerBackground" format="reference" />
  </declare-styleable>
</resources>

, :

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="Theme" parent="android:Theme">
        <item name="headerBackground">@drawable/header</item>
    </style>
</resources>

, View, , Drawable . Android .

+3

Source: https://habr.com/ru/post/1732893/


All Articles