在android中添加自定义单选按钮

我正在尝试为android中的常规按钮获得单选按钮效果

下面我有一个简单的android单选按钮

这方面的代码是

活动\u main.xml

<RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android"
xmlns:tools=”http://schemas.android.com/tools"
android:layout\u width=“匹配父项”
android:layout\u height=“match\u parent”
android:paddingBottom=“@dimen/activity\u vertical\u margin”
android:paddingLeft=“@dimen/activity\u水平\u边距”
android:paddingRight=“@dimen/activity\u水平\u边距”
android:paddingTop=“@dimen/activity\u vertical\u margin”
工具:context=“.MainActivity”>
<单选
android:id=“@+id/radiogroup 1”
android:layout\u width=“包装内容”
android:layout\u height=“包装内容”
android:layout\u centerHorizontal=“true”
android:layout\u centerVertical=“true”>
<单选按钮
android:id=“@+id/radio0”
android:layout\u width=“包装内容”
android:layout\u height=“包装内容”
android:checked=“true”
android:text=“RadioButton1”/>
<单选按钮
android:id=“@+id/radio1”
android:layout\u width=“包装内容”
android:layout\u height=“包装内容”
android:text=“RadioButton2”/>
<单选按钮
android:id=“@+id/radio2”
android:layout\u width=“包装内容”
android:layout\u height=“包装内容”
android:text=“RadioButton3”/>
&lt/放射组>
&lt/相对寿命>

如何按如下方式进行自定义:

谢谢

[编辑]使用其中一个答案中的代码

但是按钮名称被“选择如何删除”选项所掩盖?


{编辑}更多更改

最后的更改应该至少我应该知道我在三个单选按钮中选择了哪个按钮。。。。有可能得到以下信息吗

添加一个可绘制的背景以引用图像或选择器(如下所示),并使按钮透明:

<单选按钮
android:id=&[email protected]+id/radio0“;
android:layout_width="包装“U内容”;
android:layout_height="包装“U内容”;
android:background=&[email protected]空"
安卓:按钮=&[email protected]可拉拔/您的按钮背景“;
android:checked="“真的”;
android:text="RadioButton1“/&燃气轮机;

如果您希望单选按钮在选中时具有不同的资源,请创建一个可绘制的选择器背景:

res/drawable/yourbuttonbackground.xml

<选择器xmlns:android="http://schemas.android.com/apk/res/android" &燃气轮机;
<项目
android:drawable=&[email protected]“可提取的/b”;
android:state_checked="“真的”;
安卓:状态为“按下”;“真的”/&燃气轮机;
<项目
android:drawable=&[email protected]可提取的/a“;
安卓:状态为“按下”;“真的”/&燃气轮机;
<项目
android:drawable=&[email protected]可提取的/a“;
android:state_checked="“真的”/&燃气轮机;
<项目
android:drawable=&[email protected]“可提取的/b”/&燃气轮机;
&lt/选择器>

在上面的选择器中,我们引用了两个可绘图项,ab,下面是创建它们的方法:

res/drawable/a.xml-选定状态

<形状
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="矩形“&燃气轮机;
<角
android:radius="5dp“/&燃气轮机;
<固体
android:color=&quot#fff&quot/&燃气轮机;
<(打、击等的)一下
android:width="2dp“;
android:color=&quot#53aade“/&燃气轮机;
&lt/形状>

res/drawable/b.xml-常规状态

<形状
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="矩形“&燃气轮机;
<角
android:radius="5dp“/&燃气轮机;
<固体
android:color=&quot#fff&quot/&燃气轮机;
<(打、击等的)一下
android:width="2dp“;
android:color=&quot#555555“/&燃气轮机;
&lt/形状>

更多关于抽绳的信息,请点击此处:http://developer.android.com/guide/topics/resources/drawable-resource.html

发表评论