如何创建此切换按钮? [英] How to create this toggle button?

查看:85
本文介绍了如何创建此切换按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建看起来像这样的切换按钮?

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

当前我有以下内容:

        <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.

推荐答案

尝试一下,

build.gradle

build.gradle

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

}

@ style / RadioButton

@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>

这篇关于如何创建此切换按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆