简体   繁体   English

android中如何自定义单选按钮

[英]How to customize radio button in android

I am creating radio button in android application but i want to make it customized.我正在 android 应用程序中创建单选按钮,但我想对其进行自定义。 But i don't know how to do it.但我不知道该怎么做。 I want image as icon and text under the icon as in this image shown.Also i want to change the color whenever any radiobutton is selected.我想要图像作为图标和图标下方的文本,如图所示。此外,我想在选择任何单选按钮时更改颜色。

在此处输入图像描述

This type of radio button i want.我想要这种类型的单选按钮。 Please tell me how can i make it?请告诉我我该怎么做?

You Can use Custom Background您可以使用自定义背景

<RadioButton
   android:id="@+id/radioButtom"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:background="@null"
   android:button="@drawable/custom_background"
   android:checked="true"
   android:text="Your Text" />

Here is Custom_background.xml这是Custom_background.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
    android:drawable="@drawable/your_regular_state_drawable"
    android:state_checked="true"
    android:state_pressed="true" />
<item
    android:drawable="@drawable/your_selected_state_drawable"
    android:state_pressed="true" />
<item
    android:drawable="@drawable/your_selected_state_drawable"
    android:state_checked="true" />
<item
    android:drawable="@drawable/your_regular_state_drawable" />

Referance: You can get e better description from here https://stackoverflow.com/a/19163987/12676247参考:您可以从这里获得更好的描述https://stackoverflow.com/a/19163987/12676247

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM