Android: Where to find the RadioButton Drawable?

前端 未结 3 500
灰色年华
灰色年华 2021-01-18 03:28

Ok, I am trying to create a custom view called CheckedRelativeLayout.

It\'s purpose is the same as a CheckedTextView, to be able to use it

3条回答
  •  难免孤独
    2021-01-18 04:04

    For sake of completeness:

    Here some code pieces that show how you I got it working with above accepted answer.

     //Image Setup (Once when creating this view)
     ImageView indicator = (ImageView) findViewById(R.id.RadioStatusImage);
     indicator.setImageDrawable(getResources().getDrawable(android.R.drawable.btn_radio));
    
     //State Change (In some other method)
      android.R.attr.state_checked
      if (isChecked)
      {
         indicator.setImageState(android.R.attr.state_checked, false);
      }
      else
      {
         indicator.setImageState(View.ENABLED_STATE_SET, false);
      }
      invalidate();
    

提交回复
热议问题