How to get a string from attr with reference format type?

后端 未结 2 2019
孤城傲影
孤城傲影 2021-02-15 13:27

I have my custom attr.xml document in which I specified declare-styleable:




        
2条回答
  •  隐瞒了意图╮
    2021-02-15 13:38

    There's an excellent general answer which I recommend you to refer to: Declaring a custom android UI element using XML

    In particular, you should use Context.obtainStyledAttributes(AttributeSet set, int[] attrs) and TypedArray.getString(int index) instead of AttributeSet.getAttributeValue(...):

    TypedArray ta = activityContext.obtainStyledAttributes(attrs, R.styleable.EditTextValidateablePreference);
    String theString = ta.getString(R.styleable.EditTextValidateablePreference_errorMessage);
    ta.recycle();
    

提交回复
热议问题