Having the custom view TestView and declaring the following custom attribute:

<declare-styleable name="TestView">
    <attr name="testAttr" format="reference"/>
</declare-styleable>

upon trying to open the resource selection dialog from the attribute overview in the visual editor of Android Studio, the dialog opens and only allows for string resources to be selected. How can the above be modified to show the same dialog that appears when selecting the background resource for a view?

The undesired dialog

The desired dialog

Thanks in advance for your help! =)

EDIT------

I tried modifying the code to be:

<declare-styleable name="TestView">
    <attr name="testAttr" format="reference|color" />
</declare-styleable>

as this is what I found android:background to be, but the dialog to only select color resources opens instead.

The new undesired dialog

1

There are 1 best solutions below

3
On

If you want to create a new color you need to write this code at colors.xml, inside "values": (replace the hex number for the color you want)

<color name="white">#ffffff</color>

Then, once you create it, call it like that at activity_main.xml: (in the case you want to modify a textlayout)

android:textColor="@color/white"

Hope this solves your problem :)