问题描述
我想这种样子。他们似乎不喜欢标签
所以我相信他们是按钮。
I want this kind of look. They don't seem like tabs
so I believe they are buttons.
我能够通过保持一个选择在绘制获得了这幅相似的类型与切换按钮
。
I am able to acheive the similar type with toggle button
by keeping a selector in drawable.
<ToggleButton
android:id="@+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="@drawable/custom_selector"
android:textOn=" Button1 Button2"
android:textOff=" Button1 Button2" />
但他们只有两个值,并通过单击所选选项卡上获取其他选择和present一条未选。但我想酷似标签。因此,有人可以帮我实现吗?先谢谢了。
But they have only two values and by clicking on the selected tab gets the other selected and the present one unselected. But I want exactly like tab. So can someone please help me achieve it? Thanks in advance.
推荐答案
您必须创建选择的所有按钮,并使用 RadioGroup中
与选择的背景和空键..
You have to create selector for all button and use RadioGroup
with selector background and null button..
请@Andru答案创建选择。
Follow @Andru answer for create Selector..
下面是RadioGroup中code。
Below is RadioGroup code.
<RadioGroup
android:id="@+id/rdogrp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:gravity="center"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:background="@drawable/btn1Selector"
android:button="@null"
android:checked="true"
android:gravity="center" />
<RadioButton
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:background="@drawable/btn2Selector"
android:button="@null"
android:gravity="center" />
<RadioButton
android:id="@+id/btn3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:background="@drawable/btn3Selector"
android:button="@null"
android:gravity="center" />
<RadioButton
android:id="@+id/btn4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:background="@drawable/btn4Selector"
android:button="@null"
android:gravity="center" />
</RadioGroup>
下面是示例$ C $下 btn1Selector.xml
here is sample code for btn1Selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/btn1_selected" android:state_checked="true" />
<item android:drawable="@drawable/btn1_normal" android:state_checked="false"/>
</selector>
这篇关于使看起来像选项卡中的Android按键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!