How to add button tint programmatically

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

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

15条回答
  •  孤城傲影
    2020-12-01 00:21

    There are three options for it using setBackgroundTintList

    int myColor = Color.BLACK;
    
    1. button.setBackgroundTintList(new ColorStateList(EMPTY, new int[] { myColor }));
    2. button.setBackgroundTintList(ColorStateList.valueOf(myColor));
    3. button.setBackgroundTintList(contextInstance.getResources().getColorStateList(R.color.my_color));

提交回复
热议问题