How do I compare a background Image resource TextView with a R.drawable.bg_image for switch

前端 未结 1 1900
情歌与酒
情歌与酒 2020-12-18 10:24

Sorry for my bad English.

I have one TextView and it have a Background image resource. But i need when i click in this TextView the Android compare the current Backg

相关标签:
1条回答
  • 2020-12-18 11:18

    You can't get a drawable's resource id after setting this drawable as a background. But you can store some kind of flag or even a resource id somewhere outside your TextView or maybe in its tag field. In this case you'll be able to get it and compare with another id.

    Object tag = textView.getTag();
    int backgroundId = R.drawable.bg_image_2;
    if( tag != null && ((Integer)tag).intValue() == backgroundId) {
        backgroundId = R.drawable.bg_image_1;
    }
    textView.setTag(backgroundId);
    textView.setBackgroundResource(backgroundId);
    
    0 讨论(0)
提交回复
热议问题