2

i use this code for make new radio button and add it to radioGroup

            RadioButton buttonh = new  RadioButton(getApplicationContext());
            RadioGroup.LayoutParams params_rb = new RadioGroup.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);

            buttonh.setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
            buttonh.setGravity(Gravity.START);
            params_rb.setMargins(0, 0, 12, 0);
            buttonh.setTextColor(getResources().getColor(R.color.textColor));
            buttonh.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START);
            buttonh.setText(Html.fromHtml(mscs.get("time_am")));
            radiox.addView(buttonh,params_rb);

and its work but its show different color of circle so i must change it to

  AppCompatRadioButton buttonh = new AppCompatRadioButton(this);

but when i use this code the circle gone only the text shown any idea ?

also i try to add color to circle but seems there are no circle only text

       ColorStateList colorStateList = new ColorStateList(
                    new int[][]{
                            new int[]{-android.R.attr.state_checked},
                            new int[]{android.R.attr.state_checked}
                    },
                    new int[]{

                            Color.DKGRAY
                            , Color.rgb (242,81,112),
                    }
            );
            buttonh.setSupportButtonTintList(colorStateList);
Mohamed Mohamed
  • 379
  • 1
  • 5
  • 12

1 Answers1

2

First, you should take a look to appCompat lib article there and to different attributs you can set:

colorPrimary: The primary branding color for the app. By default, this is the color applied to the action bar background.

colorPrimaryDark: Dark variant of the primary branding color. By default, this is the color applied to the status bar (via statusBarColor) and navigation bar (via navigationBarColor).

colorAccent: Bright complement to the primary branding color. By default, this is the color applied to framework controls (via colorControlActivated).

colorControlNormal: The color applied to framework controls in their normal state.

colorControlActivated: The color applied to framework controls in their activated (ex. checked, switch on) state.

colorControlHighlight: The color applied to framework control highlights (ex. ripples, list selectors).

colorButtonNormal: The color applied to framework buttons in their normal state. With previous attributs you can define your own theme for RadioButton:

<style name="Theme.MyRadioButton" parent="Theme.AppCompat.Light">
    <!-- colorPrimary is used for the default action bar background -->
    <item name="colorPrimary">@color/my_awesome_color</item>

    <!-- colorPrimaryDark is used for the status bar -->
    <item name="colorPrimaryDark">@color/my_awesome_darker_color</item>

    <!-- colorAccent is used as the default value for colorControlActivated,
         which is used to tint widgets -->
    <item name="colorAccent">@color/accent</item>

    <!-- You can also set colorControlNormal, colorControlActivated
         colorControlHighlight, and colorSwitchThumbNormal. -->

</style>

and :

<RadioButton
    ....................................
    android:theme="@style/Theme.MyRadioButton">
</RadioButton>
Salauddin Gazi
  • 1,497
  • 1
  • 13
  • 18