【问题标题】:Android Radio Button background overlapping the default circleAndroid单选按钮背景与默认圆圈重叠
【发布时间】:2018-10-13 07:01:48
【问题描述】:

我的应用中有一个单选按钮,其背景设置为自定义形状。现在我看到 2 个圆圈,默认和自定义。我尝试使用 android:button=@null。它会删除整个背景。有没有其他方法可以删除默认的单选按钮圆圈。下面是我的 Xml 文件。

Radiobutton.xml:

RadioButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scaleX="0.3"
    android:scaleY="0.3"
    android:button="@android:color/transparent"
     android:background="@drawable/radio_selector"
    android:id="@+id/radio1"/>

radio_selector.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:drawable="@drawable/radio_check"
        android:state_checked="true" />
    <item
        android:state_checked="false"
        android:drawable="@drawable/radio_uncheck"
        >

    </item>
</selector>

radio_uncheck.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <solid
        android:color="#ffffff"></solid>
    <stroke
        android:color="#bb2b67"
        android:width="2dp"></stroke>
</shape>

radio_check.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <solid
        android:color="#bb2b67">
    </solid>
</shape>

【问题讨论】:

  • 仍然无法正常工作....
  • 什么不工作?我在您的代码中没有看到任何selector。请用完整的代码编辑问题。
  • 我刚刚创建了选择器并尝试了它。没有用。我将编辑它..
  • 现在编辑问题

标签: android radio-button


【解决方案1】:

当我遇到此类问题时,我使用了以下解决方案:-

<RadioButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scaleX="0.3"
    android:scaleY="0.3"
    android:button="@drawable/radio_uncheck"
    android:id="@+id/radio1"/>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-28
    • 1970-01-01
    • 2022-12-12
    • 1970-01-01
    • 2012-05-21
    相关资源
    最近更新 更多