我正在尝试为Android中的单选按钮实现自定义图标。也就是说,我希望单选按钮图标是我选择的自定义图标之一。我能够通过单选按钮内的android:button
属性来实现这一点,但我不知道如何在用户点击它时定义它。在我的应用程序中,当用户单击它时什么都没有发生。我还遵循了这里的指南。
I have 2 images :
A. tire.png (When the radio button is not clicked)
B. tireinvert.png (When the radio button is clicked)
我的RadioButton.xml文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.techfrk.customizeradiobutton.MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<RadioGroup
android:id="@+id/newexprgrp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/tvllocrbtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="20dp"
android:layout_marginTop="40dp"
android:text="Travelling Expense (Local)"
/>
<RadioButton
android:id="@+id/tvloutrbtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="20dp"
android:layout_marginTop="15dp"
android:text="Travelling Expense (Outstation)"
/>
<RadioButton
android:id="@+id/phnexprbtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="20dp"
android:layout_marginTop="15dp"
android:text="Phone Expense"
/>
<RadioButton
android:id="@+id/miscexprbtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="20dp"
android:layout_marginTop="15dp"
android:text="Misc Expense"
/>
</RadioGroup>
</RelativeLayout>
请问有人可以指导我吗?