Android - How to programmatically set button color

后端 未结 3 814
深忆病人
深忆病人 2020-12-16 18:54

I am reading in some data from a REST api and need to generate some buttons based on the information the app receives.

Because I need the same buttons in many Activi

3条回答
  •  佛祖请我去吃肉
    2020-12-16 19:33

    The getColor() function is deprecated from API level 23. Check this link for more details.
    Below is the source code from the support library:

    public static final int getColor(Context context, int id) {
        final int version = Build.VERSION.SDK_INT;
        if (version >= 23) {
            return ContextCompatApi23.getColor(context, id);
        } else {
            return context.getResources().getColor(id);
       }
    }
    

提交回复
热议问题