How to programmatically set style attribute in a view

前端 未结 11 2192
北恋
北恋 2020-11-22 06:38

I\'m getting a view from the XML with the code below:

Button view = (Button) LayoutInflater.from(this).inflate(R.layout.section_button, null);
11条回答
  •  广开言路
    2020-11-22 07:05

    Depending on what style attributes you'd like to change you may be able to use the Paris library:

    Button view = (Button) LayoutInflater.from(this).inflate(R.layout.section_button, null);
    Paris.style(view).apply(R.style.YourStyle);
    

    Many attributes like background, padding, textSize, textColor, etc. are supported.

    • List of currently supported attributes
    • Installation instructions

    Disclaimer: I authored the library.

提交回复
热议问题