Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

meaning of format reference in android attribute

Let's start with an example

<attr name="spinnerDropDownItemStyle" format="reference" />

How do I take this apart and understand it?

I watch the Android themes & styles demystified - Google I/O 2016 talk multiple times and I still don't understand how this reference thing works.

like image 414
Nouvel Travay Avatar asked Jul 29 '16 20:07

Nouvel Travay


People also ask

What is declare Styleable?

Keywords: Mobile Android Attribute. 1. declare-style leable defines some attributes, writes some identical attributes together, defines a name, or can be directly defined. In the following two ways, just use declare-style leable to organize similar attributes together.


1 Answers

reference format is used when the attribute refers to another resource ID. For example:

<!-- Declaration -->
<attr name="mydrawale" format="reference" />

<!-- Usage -->
app:mydrawable="@drawable/shape1"

So, resources like @layout/..., @color/..., @style/... are of type reference. However attribute formats like color, boolean, etc need also color literals (e.g. 0x00FF00) and boolean literals (e.g. true) respectively.

In your case, spinnerDropDownItemStyle is an attribute that gets a resource like @style/... which by itself is a pointer to a resource entry of type style.

By the way, you can set the format to multiple types using |. For example for the following attribute both @color/mycolor and 0x00FF00 are acceptable.

<attr name="mycolor" format="reference|color" />
like image 117
frogatto Avatar answered Sep 30 '22 14:09

frogatto