1

I am trying to set drawable in xml of my CustomView. but it is not showing my app:enableProgressRes="@drawable/vbequalizer_bg" or customname:enableProgressRes="@drawable/vbequalizer_bg"

I mean custom attributes are not included. As we hit Ctrl+Space android:attr shows.

And i have tried including these namespaces one by one to the Root Layout.

xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:custom="http://schemas.android.com/apk/res-auto"
xmlns:customname="http://schemas.android.com/apk/res/zare.custom.views"

But my attributes aren't accessible in xml. by anyOne of them

This answer says that the Problem is resolved after ADT 17.

attrs.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <declare-styleable name="VolumnBar">
        <attr name="disableProgressRes" format="integer" />
        <attr name="enableProgressRes" format="integer" />
    </declare-styleable>
</resources>

CustomView(VolumeBar) Constructor

public VolumnBar(Context context, AttributeSet attributeset)
{
    super(context, attributeset);

    if(!isInEditMode())
    {
        TypedArray a = context.obtainStyledAttributes(attributeset, R.styleable.VolumnBar);//VolumnBar same name as Class Name

        try
        {
            drawableProgress = a.getDrawable(R.styleable.VolumnBar_disableProgressRes);

            drawableInvalidateProgress = a.getDrawable(R.styleable.VolumnBar_enableProgressRes);
        }
        catch (Exception e)
        {

        }
        finally
        {
            a.recycle();
        }
    }
}
Community
  • 1
  • 1
Zar E Ahmer
  • 33,936
  • 20
  • 234
  • 300

1 Answers1

1

The proper format for drawable resources is reference, no integer. Change your attribute definitions to something like this:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="VolumnBar">
        <attr name="disableProgressRes" format="reference" />
        <attr name="enableProgressRes" format="reference" />
    </declare-styleable>
</resources>
ivagarz
  • 2,434
  • 22
  • 22
  • yes the proper format of it is reference. but I have created some Custom View using integer and they are working fine. And after testing your code problem doesn't solve. – Zar E Ahmer Jun 03 '15 at 13:55