本文介绍了如何在Android中将图像作为单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用中,我想从用户那里获得调查答案。所以,我已经决定将笑脸图像作为单选按钮。在Android上有可能吗?

In my app, I want to get survey answers from the user. So, I've decided put smiley images to act as a radio buttons. Is it possible on android?

例如,当用户触摸图像时,我将显示笑脸图像,它将像单选按钮一样被激活。一次,他们将被允许只选择一个。如果有人可以指导我,我将不胜感激。

For example, I will show smiley images when user touches the image and it will be activated like a radio button. At a time, they will be allowed to only choose one. If anyone could guide me, I would appreciate it.

示例:

提前致谢!

推荐答案

此问题已在以下内容中得到解答@ Benito-Bertoli

This question has been answered before Below is from @Benito-Bertoli

为您的radiobutton提供自定义样式:

Give your radiobutton a custom style:

<style name="MyRadioButtonStyle" parent="@android:style/Widget.CompoundButton.RadioButton">
    <item name="android:button">@drawable/custom_btn_radio</item>
</style>

custom_btn_radio.xml

custom_btn_radio.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
   <item android:state_checked="true" android:state_window_focused="false"
      android:drawable="@drawable/btn_radio_on" />
   <item android:state_checked="false" android:state_window_focused="false"
      android:drawable="@drawable/btn_radio_off" />

   <item android:state_checked="true" android:state_pressed="true"
      android:drawable="@drawable/btn_radio_on_pressed" />
   <item android:state_checked="false" android:state_pressed="true"
      android:drawable="@drawable/btn_radio_off_pressed" />

   <item android:state_checked="true" android:state_focused="true"
      android:drawable="@drawable/btn_radio_on_selected" />
   <item android:state_checked="false" android:state_focused="true"
      android:drawable="@drawable/btn_radio_off_selected" />

   <item android:state_checked="false" android:drawable="@drawable/btn_radio_off" />
   <item android:state_checked="true" android:drawable="@drawable/btn_radio_on" />
</selector>

用自己的替换抽奖。

这篇关于如何在Android中将图像作为单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 13:26