Created
July 24, 2013 06:36
-
-
Save tatuas/6068471 to your computer and use it in GitHub Desktop.
Androidでオリジナルのラジオグループデザインをつくる方法。
my_radio_btn.xmlをres/drawableに作り、styles.xmlにstyleタグで追加。
activity_main.xmlなどで例のように宣言すればオリジナルラジオグループの完成。 サンプルはグラフィカルなiOS風になっている。
ラジオボタンのあの丸も消去してすっきりなサンプル。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<RadioGroup | |
android:id="@+id/radiogroup" | |
android:layout_width="fill_parent" | |
android:layout_height="wrap_content" | |
android:gravity="center_horizontal" | |
android:orientation="horizontal" > | |
<RadioButton | |
android:id="@+id/radio_btn_1" | |
style="@style/MyRadioButton" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:background="@drawable/my_radio_btn" | |
android:checked="false" | |
android:text="1" /> | |
<RadioButton | |
android:id="@+id/radio_btn_2" | |
style="@style/MyRadioButton" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="right|top" | |
android:background="@drawable/my_radio_btn" | |
android:checked="false" | |
android:text="2" /> | |
</RadioGroup> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | |
<item android:shape="rectangle" android:state_checked="true"> | |
<shape android:shape="rectangle"> | |
<gradient android:angle="90" android:endColor="#444444" android:startColor="#ffffff" /> | |
<stroke android:width="2dp" android:color="#333333" /> | |
<padding android:bottom="10dip" android:left="10dip" android:right="10dip" android:top="10dip" /> | |
<corners android:radius="5dip" /> | |
</shape> | |
</item> | |
<item android:shape="rectangle" android:state_checked="false"> | |
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> | |
<stroke android:width="1dp" android:color="#333333" /> | |
<gradient android:angle="90" android:endColor="#ffffff" android:startColor="#444444" /> | |
<padding android:bottom="10dip" android:left="10dip" android:right="10dip" android:top="10dip" /> | |
<corners android:radius="1dip" /> | |
</shape> | |
</item> | |
</selector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<resources> | |
<style name="MyRadioButton" parent="android:Widget.CompoundButton.RadioButton"> | |
<item name="android:button">@null</item> | |
</style> | |
</resources> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment