Skip to content

Instantly share code, notes, and snippets.

@vuhung3990
Created December 4, 2016 22:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vuhung3990/b212ec93a3977dded1ab76826cc43a22 to your computer and use it in GitHub Desktop.
Save vuhung3990/b212ec93a3977dded1ab76826cc43a22 to your computer and use it in GitHub Desktop.
custom background state on toggle radio group button
<RadioGroup
android:orientation="horizontal"
android:id="@+id/radio_group"
android:layout_width="match_parent"
android:checkedButton="@+id/bt1"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/bt1"
android:background="@drawable/toggle_bg"
android:layout_weight="1"
android:text="Left"
android:textColor="@color/colorPrimary"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RadioButton
android:id="@+id/bt2"
android:background="@drawable/toggle_bg"
android:layout_weight="1"
android:textColor="@color/colorPrimary"
android:text="right"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RadioGroup>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true"> <!-- selected -->
<shape>
<solid android:color="@android:color/white" />
<stroke android:width="3px" android:color="@android:color/holo_blue_bright" />
<corners android:radius="5dp" />
</shape>
</item>
<item android:state_checked="false"> <!-- default -->
<shape>
<solid android:color="@android:color/black" />
<stroke android:width="1px" android:color="@android:color/darker_gray" />
<corners android:radius="5dp" />
</shape>
</item>
</selector>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment