1
我试图设置在我的CustomView的xml中可绘制。但它不显示我的app:enableProgressRes="@drawable/vbequalizer_bg"
或customname:enableProgressRes="@drawable/vbequalizer_bg"
xml无法访问自定义视图属性android
我的意思是自定义属性不包括在内。当我们点击Ctrl+Space
android:attr shows。
而且我已经试过将这些命名空间逐个包含到根布局中。
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();
}
}
}
是的正确格式是引用。但我已经使用整数创建了一些自定义视图,并且它们工作正常。经过测试,你的代码问题没有解决。 – Nepster
您还可以参阅http://stackoverflow.com/a/6108156/3496570 – Nepster