2015-06-03 2 views
1

Я пытаюсь установить , выгружаемый в xml моего CustomView. но это не показывает мой app:enableProgressRes="@drawable/vbequalizer_bg" или customname:enableProgressRes="@drawable/vbequalizer_bg"Атрибуты пользовательского вида недоступны в xml android

Я имею в виду пользовательские атрибуты не включены. Когда мы нанесли Ctrl+Space андроид: атр показывает.

И я попытался включить эти пространства имен один за другим в 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" 

Но мои атрибуты не доступны в XML. кем-либо из них

This answer says, что проблема будет решена после 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) Конструктор

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(); 
     } 
    } 
} 

ответ

0

Правильный формат для d сырьевые ресурсы reference, нет integer. Измените свои определения атрибутов примерно так:

<?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> 
+0

Да, соответствующий формат является ссылкой. но я создал некоторый пользовательский вид, используя целое число, и они работают нормально. И после тестирования ваша проблема с кодом не решена. – Nepster

+0

Вы также можете увидеть http://stackoverflow.com/a/6108156/3496570 – Nepster

Смежные вопросы