Java Code Examples for android.widget.RadioButton#setButtonDrawable()
The following examples show how to use
android.widget.RadioButton#setButtonDrawable() .
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: FlatTabGroup.java From support with Apache License 2.0 | 7 votes |
private void generateTabView(Context context, AttributeSet attrs) { if (mItemString == null) { return; } mTabViewIds = new int[mItemString.length]; int i = 0; for (String text : mItemString) { RadioButton button = new RadioButton(context, attrs); button.setGravity(Gravity.CENTER); button.setButtonDrawable(android.R.color.transparent); button.setText(text); button.setTextColor(mTextColor); button.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize); int id = generateViewId(); button.setId(mTabViewIds[i++] = id); addView(button, new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 1)); } }
Example 2
Source File: TintHelper.java From a with GNU General Public License v3.0 | 6 votes |
public static void setTint(@NonNull RadioButton radioButton, @ColorInt int color, boolean useDarker) { ColorStateList sl = new ColorStateList(new int[][]{ new int[]{-android.R.attr.state_enabled}, new int[]{android.R.attr.state_enabled, -android.R.attr.state_checked}, new int[]{android.R.attr.state_enabled, android.R.attr.state_checked} }, new int[]{ // Rdio button includes own alpha for disabled state ColorUtil.stripAlpha(ContextCompat.getColor(radioButton.getContext(), useDarker ? R.color.ate_control_disabled_dark : R.color.ate_control_disabled_light)), ContextCompat.getColor(radioButton.getContext(), useDarker ? R.color.ate_control_normal_dark : R.color.ate_control_normal_light), color }); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { radioButton.setButtonTintList(sl); } else { Drawable d = createTintedDrawable(ContextCompat.getDrawable(radioButton.getContext(), R.drawable.abc_btn_radio_material), sl); radioButton.setButtonDrawable(d); } }
Example 3
Source File: BannerView.java From MvpRoute with Apache License 2.0 | 6 votes |
@NonNull private RadioButton initData(int length, int i, Object imagepath) { initImageView(i, imagepath); RadioButton radioButton = new RadioButton(context); if (selectTab != 0) { radioButton.setBackgroundResource(selectTab); radioButton.setButtonDrawable(context.getResources().getDrawable(android.R.color.transparent)); } RadioGroup.LayoutParams buttonParams = new RadioGroup.LayoutParams(tabWidth, tabHeight); if (i != length - 1) { buttonParams.setMargins(0, 0, tabMargin, 0); } radioButton.setLayoutParams(buttonParams); radioButton.setId(i); if (i == 0) radioButton.setChecked(true); return radioButton; }
Example 4
Source File: TintHelper.java From MyBookshelf with GNU General Public License v3.0 | 6 votes |
public static void setTint(@NonNull RadioButton radioButton, @ColorInt int color, boolean useDarker) { ColorStateList sl = new ColorStateList(new int[][]{ new int[]{-android.R.attr.state_enabled}, new int[]{android.R.attr.state_enabled, -android.R.attr.state_checked}, new int[]{android.R.attr.state_enabled, android.R.attr.state_checked} }, new int[]{ // Radio button includes own alpha for disabled state ColorUtil.stripAlpha(ContextCompat.getColor(radioButton.getContext(), useDarker ? R.color.ate_control_disabled_dark : R.color.ate_control_disabled_light)), ContextCompat.getColor(radioButton.getContext(), useDarker ? R.color.ate_control_normal_dark : R.color.ate_control_normal_light), color }); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { radioButton.setButtonTintList(sl); } else { Drawable d = createTintedDrawable(ContextCompat.getDrawable(radioButton.getContext(), R.drawable.abc_btn_radio_material), sl); radioButton.setButtonDrawable(d); } }
Example 5
Source File: RecyclerViewScrollActivity.java From AndroidDemo with MIT License | 6 votes |
private void initTab() { int padding = Tools.dip2px(this, 10); for (int i = 0; i < 20; i++) { RadioButton rb = new RadioButton(this); rb.setPadding(padding, 0, padding, 0); rb.setButtonDrawable(null); rb.setGravity(Gravity.CENTER); rb.setTag(i * 5); rb.setText("Group " + i); rb.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14); try { rb.setTextColor(getResources().getColorStateList(R.color.bg_tab_text)); } catch (Exception e) { e.printStackTrace(); } rb.setCompoundDrawablesWithIntrinsicBounds(null, null, null, getResources().getDrawable(R.drawable.bg_block_tab)); rb.setOnCheckedChangeListener(onCheckedChangeListener); rg_tab.addView(rb); } ((RadioButton) rg_tab.getChildAt(0)).setChecked(true); }
Example 6
Source File: Easel.java From andela-crypto-app with Apache License 2.0 | 6 votes |
/** * Tint the radio button * * @param radioButton the radio button * @param color the color */ public static void tint(@NonNull RadioButton radioButton, @ColorInt int color) { final int disabledColor = getDisabledColor(radioButton.getContext()); ColorStateList sl = new ColorStateList(new int[][]{ new int[]{android.R.attr.state_enabled, -android.R.attr.state_checked}, new int[]{android.R.attr.state_enabled, android.R.attr.state_checked}, new int[]{-android.R.attr.state_enabled, -android.R.attr.state_checked}, new int[]{-android.R.attr.state_enabled, android.R.attr.state_checked} }, new int[]{ getThemeAttrColor(radioButton.getContext(), R.attr.colorControlNormal), color, disabledColor, disabledColor }); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { radioButton.setButtonTintList(sl); } else { Drawable radioDrawable = ContextCompat.getDrawable(radioButton.getContext(), R.drawable.abc_btn_radio_material); Drawable d = DrawableCompat.wrap(radioDrawable); DrawableCompat.setTintList(d, sl); radioButton.setButtonDrawable(d); } }
Example 7
Source File: MDTintHelper.java From NewsMe with Apache License 2.0 | 6 votes |
public static void setTint(@NonNull RadioButton radioButton, @ColorInt int color) { ColorStateList sl = new ColorStateList(new int[][]{ new int[]{-android.R.attr.state_checked}, new int[]{android.R.attr.state_checked} }, new int[]{ ThemeHelper.resolveColor(radioButton.getContext(), R.attr.colorControlNormal), color }); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { radioButton.setButtonTintList(sl); } else { Drawable d = DrawableCompat.wrap(ContextCompat.getDrawable(radioButton.getContext(), R.drawable.abc_btn_radio_material)); DrawableCompat.setTintList(d, sl); radioButton.setButtonDrawable(d); } }
Example 8
Source File: MDTintHelper.java From talk-android with MIT License | 6 votes |
@SuppressLint("NewApi") public static void setTint(RadioButton radioButton, int color) { ColorStateList sl = new ColorStateList(new int[][]{ new int[]{-android.R.attr.state_checked}, new int[]{android.R.attr.state_checked} }, new int[]{ DialogUtils.resolveColor(radioButton.getContext(), R.attr.colorControlNormal), color }); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { radioButton.setButtonTintList(sl); } else { Drawable d = DrawableCompat.wrap(ContextCompat.getDrawable(radioButton.getContext(), R.drawable.abc_btn_radio_material)); DrawableCompat.setTintList(d, sl); radioButton.setButtonDrawable(d); } }
Example 9
Source File: WizardFragment.java From aptoide-client-v8 with GNU General Public License v3.0 | 6 votes |
private void createRadioButtons() { // set button dimension int buttonSize = AptoideUtils.ScreenU.getPixelsForDip(10, getResources()); ViewGroup.LayoutParams buttonLayoutParams = new RadioGroup.LayoutParams(buttonSize, buttonSize); // set button margin int buttonMargin = AptoideUtils.ScreenU.getPixelsForDip(2, getResources()); ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) buttonLayoutParams; marginLayoutParams.setMargins(buttonMargin, buttonMargin, buttonMargin, buttonMargin); final int pages = viewPagerAdapter.getCount(); wizardButtons = new ArrayList<>(pages); Context context = getContext(); for (int i = 0; i < pages; i++) { RadioButton radioButton = new RadioButton(context); radioButton.setLayoutParams(buttonLayoutParams); radioButton.setButtonDrawable(android.R.color.transparent); radioButton.setBackgroundResource(R.drawable.wizard_custom_indicator); radioButton.setClickable(false); radioGroup.addView(radioButton); wizardButtons.add(radioButton); } }
Example 10
Source File: TintHelper.java From APlayer with GNU General Public License v3.0 | 6 votes |
public static void setTint(@NonNull RadioButton radioButton, @ColorInt int color, boolean useDarker) { ColorStateList sl = new ColorStateList(new int[][]{ new int[]{-android.R.attr.state_enabled}, new int[]{android.R.attr.state_enabled, -android.R.attr.state_checked}, new int[]{android.R.attr.state_enabled, android.R.attr.state_checked} }, new int[]{ // Rdio button includes own alpha for disabled state ColorUtil.stripAlpha(ContextCompat.getColor(radioButton.getContext(), useDarker ? R.color.ate_control_disabled_dark : R.color.ate_control_disabled_light)), ContextCompat.getColor(radioButton.getContext(), useDarker ? R.color.ate_control_normal_dark : R.color.ate_control_normal_light), color }); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { radioButton.setButtonTintList(sl); } else { Drawable d = createTintedDrawable( ContextCompat.getDrawable(radioButton.getContext(), R.drawable.abc_btn_radio_material), sl); radioButton.setButtonDrawable(d); } }
Example 11
Source File: WithSegmentedControlTextView.java From BigApp_Discuz_Android with Apache License 2.0 | 6 votes |
/** * radioButtons 的item必须是以new RadioButton(context)的形式代码生成的 * * @param radioButtons */ public void setSegmentedControl(List<RadioButton> radioButtons) { segmentedGroup.removeAllViews(); for (int i = 0; i < radioButtons.size(); i++) { RadioButton tempButton = radioButtons.get(i); // tempButton.setBackgroundResource(R.drawable.xxx); // 设置RadioButton的背景图片 tempButton.setButtonDrawable(android.R.color.transparent); // 设置按钮的样式 int marginTopBottom = DensityUtils.dip2px(getContext(), 5); int marginLeftRight = DensityUtils.dip2px(getContext(), 8); tempButton.setPadding(marginLeftRight, marginTopBottom, marginLeftRight, marginTopBottom); // 设置文字距离按钮四周的距离 tempButton.setText(tempButton.getText()); tempButton.setId(tempButton.getId()); segmentedGroup.addView(tempButton, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); } segmentedGroup.updateBackground(); segmentedGroup.invalidate(); }
Example 12
Source File: EmTintUtils.java From AndroidTint with Apache License 2.0 | 6 votes |
public static void setTint(@NonNull RadioButton radioButton, @ColorInt int color) { ColorStateList sl = new ColorStateList(new int[][]{ new int[]{-android.R.attr.state_checked}, new int[]{android.R.attr.state_checked} }, new int[]{ ThemeHelper.resolveColor(radioButton.getContext(), R.attr.colorControlNormal), color }); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { radioButton.setButtonTintList(sl); } else { Drawable d = DrawableCompat.wrap(ContextCompat.getDrawable(radioButton.getContext(), R.drawable.abc_btn_radio_material)); DrawableCompat.setTintList(d, sl); radioButton.setButtonDrawable(d); } }
Example 13
Source File: ViewPagerIndicator.java From EtsyBlur with Apache License 2.0 | 6 votes |
public void setPageCount(int pageCount) { this.pageCount = pageCount; removeAllViews(); for (int i = 0; i < pageCount; i++) { RadioButton rb = new RadioButton(getContext()); rb.setFocusable(false); rb.setClickable(false); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { Drawable d = ContextCompat.getDrawable(getContext(), R.drawable.indicator); rb.setButtonDrawable(d); LinearLayout.LayoutParams params = generateDefaultLayoutParams(); params.width = d.getIntrinsicWidth(); params.height = d.getIntrinsicHeight(); rb.setLayoutParams(params); } else { rb.setButtonDrawable(R.drawable.indicator); } addView(rb); } setCurrentPosition(-1); }
Example 14
Source File: DeviceFragment.java From android-showcase-template with Apache License 2.0 | 5 votes |
/** * Function to allow updates to the radio buttons UI when a security check has failed Passed * tests do not need updating due to being the default UI state * * @param uiElement - the UI element to update * @param textResource - the text resource to set the updates text for */ public void setCheckFailed(RadioButton uiElement, int textResource) { totalTestFailures++; uiElement.setText(textResource); uiElement.setTextColor(getResources().getColor(R.color.red)); uiElement.setButtonDrawable(R.drawable.baseline_warning); uiElement.setButtonTintList(ColorStateList.valueOf(getResources().getColor(R.color.red))); }
Example 15
Source File: CustomDrawableDemo.java From support with Apache License 2.0 | 4 votes |
@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()); } }
Example 16
Source File: ChatActivity.java From weixin with Apache License 2.0 | 4 votes |
/** * 设置笑脸被点击后的表情数据 */ private void setSmilingfaceData() { mV_myScrollView = new MyScrollView(this); mList_emoji = FaceConversionUtil.getInstace().emojiLists; // 添加表情页 mList_emojiAdapter = new ArrayList<EmojiAdapter>(); mV_myScrollView.removeAllViews(); for (int i = 0; i < mList_emoji.size(); i++) { // GridView的一些特殊属性: // // 1.android:numColumns=”auto_fit” //GridView的列数设置为自动 // 2.android:columnWidth=”90dp " //每列的宽度,也就是Item的宽度 // 3.android:stretchMode=”columnWidth"//缩放与列宽大小同步 // 4.android:verticalSpacing=”10dp” //两行之间的边距 // 5.android:horizontalSpacing=”10dp” //两列之间的边距 // 6.android:cacheColorHint="#00000000" //去除拖动时默认的黑色背景 // 7.android:listSelector="#00000000" //去除选中时的黄色底色 // 8.android:scrollbars="none" //隐藏GridView的滚动条 // 9.android:fadeScrollbars="true" //设置为true就可以实现滚动条的自动隐藏和显示 // 10.android:fastScrollEnabled="true" //GridView出现快速滚动的按钮(至少滚动4页才会显示) // 11.android:fadingEdge="none" //GridView衰落(褪去)边缘颜色为空,缺省值是vertical。(可以理解为上下边缘的提示色) // 12.android:fadingEdgeLength="10dip" //定义的衰落(褪去)边缘的长度 // 13.android:stackFromBottom="true" //设置为true时,你做好的列表就会显示你列表的最下面 // 14.android:transcriptMode="alwaysScroll" //当你动态添加数据时,列表将自动往下滚动最新的条目可以自动滚动到可视范围内 // 15.android:drawSelectorOnTop="false" //点击某条记录不放,颜色会在记录的后面成为背景色,内容的文字可见(缺省为false) // GridView view = new GridView(this); EmojiAdapter adapter = new EmojiAdapter(this, mList_emoji.get(i)); view.setAdapter(adapter); mList_emojiAdapter.add(adapter); view.setOnItemClickListener(this); view.setNumColumns(7); view.setBackgroundColor(Color.TRANSPARENT); // view.setHorizontalSpacing(1); //两列之间的边距 // view.setVerticalSpacing(10);//两行之间的边距 view.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);//缩放与列宽大小同步 view.setCacheColorHint(0);//去除拖动时默认的黑色背景 // view.setPadding(5, 5, 5, 5); view.setSelector(new ColorDrawable(Color.TRANSPARENT)); LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); view.setLayoutParams(params); view.setGravity(Gravity.CENTER); mV_myScrollView.addView(view); } mLl_chat_smilingface_body.removeAllViews(); mLl_chat_smilingface_body.addView(mV_myScrollView);//将MyScrollView添加到内容显示区 RadioGroup.LayoutParams params_rb = new RadioGroup.LayoutParams(DensityUtil.dip2px(this, 8), DensityUtil.dip2px(this, 8)); int marginValue = DensityUtil.dip2px(this, 3); params_rb.setMargins(marginValue, 0, marginValue, 0); for (int i = 0; i < mV_myScrollView.getChildCount(); i++) { RadioButton rbtn = new RadioButton(this); rbtn.setButtonDrawable(R.drawable.cgt_selector_chat_radiobtn_bg); rbtn.setId(i); mRg_chat_smilingface_tab.addView(rbtn, params_rb); if (i == 0) { rbtn.setChecked(true); } } /** * 监听单选按钮是否被选中, */ mRg_chat_smilingface_tab.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { current = checkedId; mV_myScrollView.moveToDest(checkedId); } }); /** * */ mV_myScrollView.setChangedListener(new IPageChangedListener() { @Override public void changedTo(int pageId) { current = pageId; ((RadioButton) mRg_chat_smilingface_tab.getChildAt(pageId)).setChecked(true); } }); }