How do I use obtainStyledAttributes(int []) with internal Themes of Android

后端 未结 4 656
说谎
说谎 2020-12-24 09:09

So I have looked around and found out that android.R.styleable is no longer part of the SDK even though it is still documented here.

That wouldn\'t real

4条回答
  •  [愿得一人]
    2020-12-24 09:47

    The CustomView API demo shows how to retrieve styled attributes. The code for the view is here:

    https://github.com/android/platform_development/blob/master/samples/ApiDemos/src/com/example/android/apis/view/LabelView.java

    The styleable array used to retrieve the text, color, and size is defined in the section here:

    https://github.com/android/platform_development/blob/master/samples/ApiDemos/res/values/attrs.xml#L24

    You can use to define any list of attributes that you want to retrieve as a group, containing both your own and ones defined by the platform.

    As far as these things being in the documentation, there is a lot of java doc around the styleable arrays that makes them useful to have in the documentation, so they have been left there. However as the arrays change, such as new attributes being added, the values of the constants can change, so the platform ones can not be in the SDK (and please do not use any tricks to try to access them). There should be no need to use the platform ones anyway, because they are each there just for the implementation of parts of the framework, and it is trivial to create your own as shown here.

提交回复
热议问题