@Override public void setTextColor(int color) { super.setTextColor(color); if (mTextHelper != null) { mTextHelper.setTextColor(); } }
@Override public void setTextColor(ColorStateList colors) { super.setTextColor(colors); if (mTextHelper != null) { mTextHelper.setTextColor(); } }
private void changeButtonStatus(int index, boolean check){ RadioButton button; switch (index){ case PAGE_COMMON: button = mCommon; break; case PAGE_TRANSLUCENT: button = mTranslucent; break; case PAGE_COORDINATOR: button = mCoordinator; break; case PAGE_COLLAPSING_TOOLBAR: button = mCollapsingToolbar; break; default: button = mCommon; } button.setOnCheckedChangeListener(null); button.setChecked(check); button.setOnCheckedChangeListener(this); if (check) { button.setTextColor(ContextCompat.getColor(this, R.color.colorAccent)); } else { button.setTextColor(ContextCompat.getColor(this, R.color.colorBlack)); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(null); setContentView(R.layout.activity_main); fragments.put(PAGE_COMMON, new CommonFragment()); fragments.put(PAGE_TRANSLUCENT, new TranslucentFragment()); fragments.put(PAGE_COORDINATOR, new DrawerFragment()); fragments.put(PAGE_COLLAPSING_TOOLBAR, new CollapsingToolbarFragment()); mCommon = (RadioButton) findViewById(R.id.common); mCommon.setOnCheckedChangeListener(this); mTranslucent = (RadioButton) findViewById(R.id.translucent); mTranslucent.setOnCheckedChangeListener(this); mCoordinator = (RadioButton) findViewById(R.id.coordinator); mCoordinator.setOnCheckedChangeListener(this); mCollapsingToolbar = (RadioButton) findViewById(R.id.collapsing_toolbar); mCollapsingToolbar.setOnCheckedChangeListener(this); FragmentTransaction ft = MainActivity.this.getSupportFragmentManager().beginTransaction(); ft.add(fragmentContentId, fragments.get(PAGE_COMMON)); currentTab = PAGE_COMMON; mCommon.setTextColor(getResources().getColor(R.color.colorAccent)); ft.commit(); }
ColorStateList csl = AppCompatResources.getColorStateList(context, R.color.my_color_state); RadioButton r = (RadioButton) findViewById(R.id.radio_button); r.setTextColor(csl);
public void onClick(View v) { //Disable buttons for (int i = 0; i < answerGroup.length; i++) { for (int j = 0; j < answer.length; j++) { answerGroup[i].getChildAt(j).setEnabled(false); } } //put button colors for(RadioButton correct: correctAnswerRadios){ correct.setTextColor(Color.GREEN); } for(RadioButton wrong: wrongAnswersRadios){ wrong.setTextColor(Color.RED); } }
/** * set tab home state */ private void setHomeState() { if (mRadioHome.isChecked()) { mRadioHome.setTextColor(ContextCompat.getColor(getActivity(), R.color.colorPrimary)); } else { mRadioHome.setTextColor(ContextCompat.getColor(getActivity(), R.color.black)); } }
private void setLikeState() { if (mRadioLike.isChecked()) { mRadioLike.setTextColor(ContextCompat.getColor(getActivity(), R.color.colorPrimary)); } else { mRadioLike.setTextColor(ContextCompat.getColor(getActivity(), R.color.black)); } }
private void setLocationState() { if (mRadioLocation.isChecked()) { mRadioLocation.setTextColor(ContextCompat.getColor(getActivity(), R.color.colorPrimary)); } else { mRadioLocation.setTextColor(ContextCompat.getColor(getActivity(), R.color.black)); } }
private void setMeState() { if (mRadioMe.isChecked()) { mRadioMe.setTextColor(ContextCompat.getColor(getActivity(), R.color.colorPrimary)); } else { mRadioMe.setTextColor(ContextCompat.getColor(getActivity(), R.color.black)); } }
RadioButton rad;//initialize first! //You can set the background color rad.setBackgroundColor(Color.BLUE); //Text color rad.setTextColor(Color.WHITE); //or highlight color rad.setHighlightColor(Color.GREEN);
public void onClick(View v) { if(selected != null) { selected.setTextColor(Color.BLACK); selected.setTextColor(Color.GREEN); public void onClick(View v) { if(selected != null) { selected.setTextColor(Color.BLACK); selected.setTextColor(Color.RED);
/** * 设置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); } }
R.drawable.selected_right_background)); femaleButton.setTextColor(getResources().getColor(R.color.Purple)); maleButton.setTextColor(getResources().getColor(R.color.Gray)); mGender = MALE; R.drawable.unselected_right_background)); femaleButton.setTextColor(getResources().getColor(R.color.Gray)); maleButton.setTextColor(getResources().getColor(R.color.Purple)); mGender = FEMALE;
@Override public void onCheckedChanged(RadioGroup group, int checkedId) { int radioButtonId = group.getCheckedRadioButtonId(); // 根据ID获取RadioButton的实例 RadioButton rb = (RadioButton) findViewById(radioButtonId); for (int i = 0; i < group.getChildCount(); i++) { RadioButton vradio = (RadioButton) group.getChildAt(i); vradio.setGravity(Gravity.CENTER); vradio.setPadding(20, 20, 20, 20); if (rb.getId() == vradio.getId()) { vradio.setTextColor(getResources().getColor(R.color.subject_select)); vradio.setChecked(true); vradio.setBackground(getResources().getDrawable(R.drawable.bg_bottom)); } else { vradio.setTextColor(getResources().getColor(R.color.kViewztblack)); vradio.setChecked(false); vradio.setBackground(null); } } // CustomProgress.show(mContext, true, null); kChartTimeInterval = titleList.get(checkedId - 1).get("time") + ""; indexMarketChart(); } });
private void createTipTextLocationChoices(LinearLayout linearLayout){ RadioGroup radioGroup = new RadioGroup(this); radioGroup.setOrientation(LinearLayout.HORIZONTAL); radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { switch (checkedId){ case R.id.radio_below: cameraMask.setTextLocation(CameraMask.LOCATION_BELOW_CAMERA_LENS); break; case R.id.radio_above: cameraMask.setTextLocation(CameraMask.LOCATION_ABOVE_CAMERA_LENS); break; } } }); linearLayout.addView(radioGroup, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); RadioButton button1 = new RadioButton(this); button1.setId(R.id.radio_below); button1.setTextColor(Color.WHITE); button1.setChecked(true); button1.setText("BelowCameraLens"); RadioButton button2 = new RadioButton(this); button2.setId(R.id.radio_above); button2.setTextColor(Color.WHITE); button2.setText("AboveCameraLens"); radioGroup.addView(button1); radioGroup.addView(button2); }
RadioButton button1 = new RadioButton(this); button1.setId(R.id.radio_camera_lens_pic); button1.setTextColor(Color.WHITE); button1.setChecked(true); button1.setText("PictureCameraLens"); RadioButton button2 = new RadioButton(this); button2.setId(R.id.radio_camera_lens_line); button2.setTextColor(Color.WHITE); button2.setText("NormalCameraLens"); radioGroup.addView(button1);
private RadioButton createRadioView() { RadioButton mRadioButton = new RadioButton(getContext(), null, mRadioStyle > 0 ? mRadioStyle : android.R.attr.radioButtonStyle); if (mRadioStyle == 0) { mRadioButton.setGravity(Gravity.CENTER); mRadioButton.setEllipsize(TruncateAt.END); } if (mTextColor != null) mRadioButton.setTextColor(mTextColor); if (textSize > 0) mRadioButton.setTextSize(textSize); return mRadioButton; }
/** * 创建子 tab * * @param context * @param id */ public static RadioButton creatTabItem(Context context, int id, String text) { final int width = DensityUtil.dip2px(context, 80); final int height = DensityUtil.dip2px(context, 46); final int padding = DensityUtil.dip2px(context, 3); RadioButton button; button = new RadioButton(context); button.setId(id); // button.setWidth(width); // button.setHeight(height); button.setText(text); button.setLayoutParams(new LinearLayout.LayoutParams(width, height)); button.setHeight(height); button.setBackgroundResource(R.drawable.tab_item_bg_selector); button.setButtonDrawable(context.getResources().getDrawable(android.R.color.transparent)); button.setGravity(Gravity.CENTER); button.setTextColor(context.getResources().getColorStateList(R.color.tab_item_font_color_selector)); button.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18); button.setPadding(0, 0, 0, padding); return button; } }
private void createRadioGroup() { final LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); if (mRadioGroup == null) { mRadioGroup = new RadioGroup(mContext); mRadioGroup.setLayoutParams(params); } else { removeView(mRadioGroup); } mRadioGroup.removeAllViews(); mRadioGroup.setOnCheckedChangeListener(this); for (ODataRow label : items) { RadioButton rdoBtn = new RadioButton(mContext); rdoBtn.setLayoutParams(params); rdoBtn.setText(label.getString(mModel.getDefaultNameColumn())); if (textSize > -1) { rdoBtn.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); } if (appearance > -1) { rdoBtn.setTextAppearance(mContext, appearance); } rdoBtn.setTextColor(textColor); mRadioGroup.addView(rdoBtn); } addView(mRadioGroup); }