1, you need to add this kind of code to the constructors of your custom view which must extend ViewGroup, and the parameter attachToRoot must be true.

    LayoutInflater.from(context).inflate(R.layout.yourLayout, this, true);

 

2,If you want to add your custom declared style, you may need to declare your custom namespace, for example,

    xmlns:wytings="http://schemas.android.com/apk/res-auto"

You will need to use this style in Java code and below code is what you need. By the way, typeArray should be recycled if not used.

    TypedArray typeArray = context.obtainStyledAttributes(attrs, R.styleable.yourStyle);

相关文章:

  • 2021-11-11
  • 2022-12-23
  • 2021-12-07
  • 2021-11-12
  • 2021-10-09
  • 2021-10-15
  • 2021-10-02
猜你喜欢
  • 2021-12-04
  • 2021-07-05
  • 2022-12-23
  • 2022-12-23
  • 2021-10-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案