Я разработал такой же макет, как показано ниже.Это может вам помочь.
<RadioButton
android:id="@+id/radioSubject"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@null"
android:button="@android:color/transparent"
android:drawableTop="@drawable/subject_selector"
android:fontFamily="@font/roboto_bold"
android:gravity="center"
android:text="@string/txt_subject"
android:textColor="@color/radio_text_selector"
android:textSize="@dimen/_15ssp" />
<Space
android:layout_width="@dimen/_10sdp"
android:layout_height="match_parent" />
<RadioButton
android:id="@+id/radioChapter"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@null"
android:button="@android:color/transparent"
android:drawableTop="@drawable/chapter_selector"
android:fontFamily="@font/roboto_bold"
android:gravity="center"
android:text="@string/txt_chapter"
android:textColor="@color/radio_text_selector"
android:textSize="@dimen/_15ssp" />
<Space
android:layout_width="@dimen/_10sdp"
android:layout_height="match_parent" />
<RadioButton
android:id="@+id/radioTopic"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@null"
android:button="@android:color/transparent"
android:drawableTop="@drawable/topic_selector"
android:fontFamily="@font/roboto_bold"
android:gravity="center"
android:text="@string/txt_topic"
android:textColor="@color/radio_text_selector"
android:textSize="@dimen/_15ssp" />
</RadioGroup>
Здесь subject_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_ico_subject_active" android:state_checked="true" />
<item android:drawable="@drawable/ic_ico_subject" />
</selector>
Вы должны создать то же самое xml
для других RadioButton
.
Если вы хотите изменить цвет текста для выбранного RadioButton
, то здесь xml.Поместите этот xml-файл в res> color>.
для цвета текста radio_text_selector.xml
.
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="@color/colorPrimary"/>
<item android:state_checked="true" android:color="@color/colorPrimary"/>
<item android:color="@color/dividerColor"/>
</selector>
Здесь вывод выглядит как
![enter image description here](https://i.stack.imgur.com/NGIFK.png)