How to add button tint programmatically

前端 未结 15 906
时光取名叫无心
时光取名叫无心 2020-11-30 23:38

In the new AppCompat library, we can tint the button this way:

15条回答
  •  醉梦人生
    2020-12-01 00:16

    According to the documentation the related method to android:backgroundTint is setBackgroundTintList(ColorStateList list)

    Update

    Follow this link to know how create a Color State List Resource.

    
    
        
    
    

    then load it using

    setBackgroundTintList(contextInstance.getResources().getColorStateList(R.color.your_xml_name));
    

    where contextInstance is an instance of a Context


    using AppCompart

    btnTag.setSupportButtonTintList(ContextCompat.getColorStateList(Activity.this, R.color.colorPrimary));
    

提交回复
热议问题