简体   繁体   中英

How to add Title and Subtitle in android RadioButton?

I want to know how to add subtitle in RadioButton in android. Like in the image below.

Radio Button with Subtitle
在此处输入图片说明

Thanks in advance...

Use RadioButton without text. And for text use TextView . Check

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <RadioButton
        android:checked="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="wrap_content"
        android:layout_height="match_parent">
        <TextView
            android:text="Phone Storage"
            android:textStyle="bold"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
        <TextView
            android:text="/storage/emulated/0/Xender"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
    </LinearLayout>
</LinearLayout>

Output:

在此处输入图片说明

This can be easily done by using A RadioButton with two TextView as mentioned by CommonsWare but there aren't any built-in widget for this.

here how is how you can achieve this.

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MapsActivity">


    <RadioButton
        android:id="@+id/rbSwitch"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:checked="true" />

    <TextView
        android:id="@+id/tvTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/rbSwitch"
        android:text="Phone Storage"
        android:textColor="@android:color/black"
        android:textSize="16sp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/tvTitle"
        android:layout_toRightOf="@id/rbSwitch"
        android:text="/storage/emulated/0/Xender" />


</RelativeLayout>

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM