Android 检索标准视图的自定义属性

Android 检索标准视图的自定义属性,android,view,custom-attributes,Android,View,Custom Attributes,我已经为EditText定义了一个自定义属性testAttribute,并将其应用到布局中。 这是按预期编译的,所以我认为它是可用的 <EditText android:layout_width="wrap_content" cst:testAttribute="true" android:layout_height="wrap_content"></EditText> 知道吗,我需要在我的操作中以编程的方式阅读testAttribute,但我不知道怎么做。

我已经为EditText定义了一个自定义属性testAttribute,并将其应用到布局中。 这是按预期编译的,所以我认为它是可用的

<EditText android:layout_width="wrap_content"   
cst:testAttribute="true"
android:layout_height="wrap_content"></EditText>

知道吗,我需要在我的操作中以编程的方式阅读testAttribute,但我不知道怎么做。 我知道如何在自定义视图中执行此操作,但我需要在标准视图中执行此操作


有人对此有想法吗?

在自定义视图中,您可以执行以下操作:

    public MyCustomView(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle); 

            final TypedArray a = context.obtainStyledAttributes(attrs,  R.styleable.MyCustomView, defStyle, 0);
            // the default value is true
            // get the custom value progammatically
            testAttribute = a.getBoolean(R.styleable.MyCustomView_testAttribute, true);

           // make sure to recycle
           a.recycle();
    }

希望有帮助

这根本不能回答问题