Reputation:
I want to design RadioGroup
like this
and I've done like this
here is my xml code
<RadioGroup
android:id="@+id/toggle"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_marginStart="49dp"
android:layout_marginLeft="49dp"
android:layout_marginTop="39dp"
android:layout_marginEnd="49dp"
android:layout_marginRight="49dp"
android:background="@drawable/pink_out_line"
android:checkedButton="@+id/search"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<RadioButton
android:id="@+id/search"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginStart="1dp"
android:layout_marginLeft="1dp"
android:layout_marginTop="1dp"
android:layout_marginBottom="1dp"
android:layout_weight="1"
android:background="@drawable/toggle_widget_background"
android:button="@null"
android:gravity="center"
android:text="Search"
android:textColor="#e87e0a" />
<RadioButton
android:id="@+id/offer"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="1dp"
android:layout_marginEnd="1dp"
android:layout_marginRight="1dp"
android:layout_marginBottom="1dp"
android:layout_weight="1"
android:background="@drawable/toggle_widget_background"
android:button="@null"
android:gravity="center"
android:text="Offers"
android:textColor="#e87e0a" />
</RadioGroup>
toggle_widget_background.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/colorPrimary" android:state_checked="true" />
<item android:drawable="@color/dark_pink" android:state_pressed="true" />
<item android:drawable="@color/transparent" />
pink_out_line.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="2dp" />
<stroke
android:width="1dp"
android:color="#f59f0b" />
Initially the color should be white and when I click on search or offer their text color should be orange. Thanks
Upvotes: 2
Views: 76
Reputation: 643
android:textColor="#e87e0a"
This is the problem.You are keeping the textColor constant, instead you should have a selector as textColor.
Please refer this answer https://stackoverflow.com/a/55139080/3400640
Upvotes: 2