<分区>
Possible Duplicate:
How to read custom attributes in Android
最近我读到有关自定义属性的内容。我想向 TextView 添加自定义属性。
到目前为止我有:
属性文件:
<resources>
<attr name="binding" format="string" />
<declare-styleable name="TextView">
<attr name="binding" />
</declare-styleable>
布局文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:custom="http://schemas.android.com/apk/res/de.innosoft.android"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
custom:binding="test"/>
给定一个 TextView
TextView tv = ...
然后我将如何获得该属性的值(即“测试”)?我阅读了有关 obtainStyledAttributes 的信息,但不知道如何在此处使用它。