示例#1
0
  @Override
  protected void applyStyle(
      Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super.applyStyle(context, attrs, defStyleAttr, defStyleRes);

    RadioButtonDrawable drawable =
        new RadioButtonDrawable.Builder(context, attrs, defStyleAttr, defStyleRes).build();
    drawable.setInEditMode(isInEditMode());
    drawable.setAnimEnable(false);
    setButtonDrawable(drawable);
    drawable.setAnimEnable(true);
  }
  @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
  private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    // a fix to reset paddingLeft attribute
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
      TypedArray a =
          context.obtainStyledAttributes(
              attrs,
              new int[] {android.R.attr.padding, android.R.attr.paddingLeft},
              defStyleAttr,
              defStyleRes);

      if (!a.hasValue(0) && !a.hasValue(1))
        setPadding(0, getPaddingTop(), getPaddingRight(), getPaddingBottom());

      a.recycle();
    }

    setClickable(true);
    applyStyle(context, attrs, defStyleAttr, defStyleRes);
  }
 public void applyStyle(int resId) {
   applyStyle(getContext(), null, 0, resId);
 }