Programmatically change drawableLeft of Button

后端 未结 5 1214
太阳男子
太阳男子 2021-02-09 00:50

I\'m using a Button

5条回答
  •  一向
    一向 (楼主)
    2021-02-09 01:14

    just follow this code i hope it's really helpful for you..

    boolean isIconChange;
    button.setOnClickListener(new OnClickListener() {
    
        @Override
        public void onClick(View arg0) {
            isIconChange = !isIconChange;
            if(isIconChange){
               button.setCompoundDrawablesWithIntrinsicBounds(R.drawable.like, 0, 0, 0);
               button.setTextColor(Color.BLACK);
            } else {
               button.setCompoundDrawablesWithIntrinsicBounds(R.drawable.dislike, 0, 0, 0);
               button.setTextColor(Color.RED);
            }
        }
    });
    

提交回复
热议问题