有什么办法可以在Android运行时获取背景可绘制

时间:2019-12-19 10:44:45

标签: java android kotlin drawable

我在单击textview时正在检查背景可绘制对象,并在运行时更改背景。是否有任何方法可以在运行时比较背景可绘制对象

tvFollowFollowing.setOnClickListener {
  //on clicking on textview tvFollowFollowing check the background drawable of textview  and change the background 
      if(tvFollowFollowing.background==ContextCompat.getDrawable(context,R.drawable.item_follow_border)){
                tvFollowFollowing.text=context.getString(R.string.following)
                tvFollowFollowing.setTextColor(ContextCompat.getColor(context,R.color.colorGreyHeader))
                tvFollowFollowing.background=ContextCompat.getDrawable(context,R.drawable.item_grey_border)
            }else {
                tvFollowFollowing.text=context.getString(R.string.follow)
                tvFollowFollowing.setTextColor(ContextCompat.getColor(context,R.color.colorWhite))
                tvFollowFollowing.background=ContextCompat.getDrawable(context,R.drawable.item_follow_border)
            }

        }

0 个答案:

没有答案
相关问题