How to create this toggle button?
Asked Answered
S

1

1

How can I create a toggle button that looks like this?

Currently I have the below:

        <RadioGroup
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:layout_weight="1">

        <ToggleButton
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:textOff="@string/toggle_button_boy_add_baby"
            android:textOn="toggle_button_boy_add_baby" />

        <ToggleButton
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:textOff="@string/toggle_button_girl_add_baby"
            android:textOn="@string/toggle_button_girl_add_baby" />

        <ToggleButton
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:textOff="@string/toggle_button_unsure_add_baby"
            android:textOn="@string/toggle_button_unsure_add_baby" />

    </RadioGroup>

Any tips or advice would be much appreciated. Thank you.

Scorpaenoid answered 1/12, 2015 at 12:10 Comment(5)
see following git repo github.com/hoang8f/android-segmented-control probably helpLagrange
https://mcmap.net/q/564078/-segment-control-in-android-closedOverseas
this one is pretty easy aswell: github.com/nairteashop/SegmentedControlSuperorder
It's actually a styled RadioGroup with custom RadioButtons.Zhao
@ρяσѕρєяK Thanks! I used this and it works great.Scorpaenoid
T
2

try this,

build.gradle

dependencies {
compile 'info.hoang8f:android-segmented:1.0.6'

}

@style/RadioButton

    <attr name="sc_corner_radius" format="dimension" />
<attr name="sc_border_width" format="dimension" />
<attr name="sc_tint_color" format="color" />
<attr name="sc_checked_text_color" format="color" />

code

     <info.hoang8f.android.segmented.SegmentedGroup
        xmlns:segmentedgroup="http://schemas.android.com/apk/res-auto"
        android:id="@+id/segmented2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:orientation="horizontal"
        segmentedgroup:sc_border_width="2dp"
        segmentedgroup:sc_corner_radius="10dp">

        <RadioButton
            android:id="@+id/button21"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="One"
            style="@style/RadioButton" />

        <RadioButton
            android:id="@+id/button22"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Two"
            style="@style/RadioButton" />

        <RadioButton
            android:id="@+id/button24"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Two"
            style="@style/RadioButton" />
    </info.hoang8f.android.segmented.SegmentedGroup>
Tufa answered 2/12, 2015 at 5:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.