可能是重复的问题:
如何在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 = ...
我该如何获取这个属性的值(它是“test”)?我了解到了obtainStyledAttributes,但不知道如何在这里使用它。