Java Code Examples for android.widget.RadioButton#setBackgroundDrawable()

The following examples show how to use android.widget.RadioButton#setBackgroundDrawable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NavView.java    From TabPager with Apache License 2.0 5 votes vote down vote up
/**
 * 设置Tab样式
 *
 * @param rb      Tab项
 * @param checked 是否选中
 */
private void setTabStyle(RadioButton rb, boolean checked) {
    if (checked) {
        rb.setTextColor(mNavTextCheckedColor);
        if (null == mNavBgCheckedImg) {
            rb.setBackgroundColor(mNavBgCheckedColor);
        } else {
            rb.setBackgroundDrawable(mNavBgCheckedImg);
        }
    } else {
        rb.setTextColor(mNavTextDefaultColor);
        rb.setBackgroundColor(Color.TRANSPARENT);
        rb.setBackgroundDrawable(null);
    }
}
 
Example 2
Source File: NavView.java    From TabPager with Apache License 2.0 5 votes vote down vote up
/**
 * 设置Tab样式
 *
 * @param rb      Tab项
 * @param checked 是否选中
 */
private void setTabStyle(RadioButton rb, boolean checked) {
    if (checked) {
        rb.setTextColor(mNavTextCheckedColor);
        if (null == mNavBgCheckedImg) {
            rb.setBackgroundColor(mNavBgCheckedColor);
        } else {
            rb.setBackgroundDrawable(mNavBgCheckedImg);
        }
    } else {
        rb.setTextColor(mNavTextDefaultColor);
        rb.setBackgroundColor(Color.TRANSPARENT);
        rb.setBackgroundDrawable(null);
    }
}
 
Example 3
Source File: CustomDrawableDemo.java    From support with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.custom_drawable_layout);
    final int color = 0xff35b558;
    int strokeWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2f, getResources().getDisplayMetrics());
    int corner = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5f, getResources().getDisplayMetrics());


    SegmentDrawable drawable1 = new SegmentDrawable(SegmentDrawable.Style.LEFT_EDGE);
    drawable1.setStrokeWidth(strokeWidth);
    drawable1.setColor(color);
    drawable1.setCornerRadius(corner);
    findViewById(R.id.label).setBackgroundDrawable(drawable1);

    SegmentDrawable drawable2 = new SegmentDrawable(SegmentDrawable.Style.MIDDLE);
    drawable2.setStrokeWidth(strokeWidth);
    drawable2.setColor(color);
    drawable2.setCornerRadius(corner);

    findViewById(R.id.label2).setBackgroundDrawable(drawable2);

    SegmentDrawable drawable3 = new SegmentDrawable(SegmentDrawable.Style.RIGHT_EDGE);
    drawable3.setStrokeWidth(strokeWidth);
    drawable3.setColor(color);
    drawable3.setCornerRadius(corner);

    findViewById(R.id.label3).setBackgroundDrawable(drawable3);

    RadioGroup group = (RadioGroup) findViewById(R.id.container);
    int count = group.getChildCount();

    for (int i = 0; i < count; i++) {
        RadioButton child = (RadioButton) group.getChildAt(i);

        SegmentDrawable drawable;
        if (i == 0) {
            drawable = new SegmentDrawable(SegmentDrawable.Style.LEFT_EDGE);
            child.setChecked(true);
        } else if (i == count - 1) {
            drawable = new SegmentDrawable(SegmentDrawable.Style.RIGHT_EDGE);
        } else {
            drawable = new SegmentDrawable(SegmentDrawable.Style.MIDDLE);
        }
        drawable.setColor(color);
        drawable.setStrokeWidth(strokeWidth);
        drawable.setCornerRadius(corner);

        child.setButtonDrawable(null);
        child.setBackgroundDrawable(drawable.newStateListDrawable());
    }
}