maoruibin / maoruibin/maoruibin.github.com
使用 Xml 自定义 Switch 样式按钮
Open
Nobody has claimed this yet.
- Dominant language
- HTML
- Stars
- 22
- Forks
- 4
- PR merge metrics
- No merged PRs in 30d
Description
示意图

代码
主布局
<RadioGroup
android:id="@+id/voteType"
android:checkedButton="@+id/rbText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/compose_round_fill"
android:orientation="horizontal">
<RadioButton
android:id="@+id/rbText"
android:text="文字"
android:button="@null"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:textColor="@drawable/compose_vote_type_color"
android:textSize="12dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/compose_vote_type_switch"/>
<RadioButton
android:id="@+id/rbImg"
android:text="图文"
android:button="@null"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:textColor="@drawable/compose_vote_type_color"
android:textSize="12dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/compose_vote_type_switch"/>
</RadioGroup>
background
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="#B8B8B8" android:width="1dp"/>
<corners android:radius="50dp"/>
</shape>
button selector
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/compose_round_fill_white" android:state_checked="true"/>
<item android:drawable="@android:color/transparent"/>
</selector>
color selector
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#939393" android:state_checked="true"/>
<item android:color="#636363"/>
</selector>
选中态
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<stroke android:color="#E9E9E9" android:width="1dp"/>
<solid android:color="#ffffff"/>
<corners android:radius="50dp"/>
</shape>
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the XML snippets in the issue, including the RadioGroup and drawable selectors, and compare them with the repository's current blog content. Done means the custom switch-style button is documented or represented as requested, including its checked-state background and text colors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, xml
- Domain
- design, mobile
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100