我是一个有用的助手,可以帮助您翻译文本。
我制作了一个库,想要将其包含在我的项目中。
在其中,我在我的attr.xml文件中添加了以下内容:
在MyCustomView.java中,我有以下代码:
我制作了一个库,想要将其包含在我的项目中。
在其中,我在我的attr.xml文件中添加了以下内容:
<declare-styleable name="MyCustomView">
<attr name="MyPrivateID" format="string"/>
</declare-styleable>
我将这个库包含在我的应用程序中,它可以正常工作。但是我无法检索到我的自定义属性。
这是我的activity_main.xml文件:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
...........>
<something.myown.MyCustomView
android:layout_width="match_parent"
android:layout_height="wrap_content"
custom:MyPrivateID="GjM4X9QfK2VT05BKlEyffkAKGLU=dhbdsljhbdDjTchvNTQwMg=="/>
在MyCustomView.java中,我有以下代码:
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MyCustomView);
try {
String string = a.getString(R.styleable.MyCustomView_MyPrivateID);
return string;
} finally {
a.recycle();
}
字符串返回为空。需要帮助。
MyPrivateID
的值? - betorcs