【问题标题】:Rectangle shape drawable won't show as checkbox selector item可绘制的矩形形状不会显示为复选框选择器项
【发布时间】:2012-06-17 11:09:12
【问题描述】:

我已经定义了一个像这样绘制的矩形:

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle">

    <corners android:radius="4dip"/>
    <solid android:color="#FF000000" />
    <stroke android:width="1dip" android:color="@color/service_checkbox_disabled_unchecked_stroke" />

</shape>

我可以毫无问题地将 drawble 显示为 imageView。但是,它应该是复选框的一种状态的可绘制对象。我的复选框按钮的选择器是这样定义的:

<selector xmlns:android="http://schemas.android.com/apk/res/android" >

    <item android:state_checked="true" android:drawable="@drawable/bg_services_tick_unchecked_disabled" />
    <item android:state_checked="false" android:drawable="@drawable/bg_services_tick_unchecked_disabled" />

</selector>

最后是我的复选框:

<CheckBox
    android:id="@+id/cb_tariff_3_next_month_checkbox"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:button="@drawable/checkbox_services"
    android:layout_centerHorizontal="true"/>

谁能告诉我,为什么这不起作用?非常感谢。

【问题讨论】:

  • 请接受以下答案。这是非常晦涩的知识点,值得承认。 (我不是海报)。

标签: android checkbox shape


【解决方案1】:

你必须给形状添加一个尺寸节点:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle"
    >
    <size android:width="30dp" android:height="30dp" />
    <solid android:color="@color/blueBase"/>
    <stroke
        android:width="1dp"
        android:color="@color/blueDark" />
</shape>

【讨论】:

  • 你拯救了我的一天。
  • 一天完成两个!想弄清楚为什么它适用于可绘制文件而不是 XML 文件。
  • 这种行为对我来说似乎很不一致。我设法通过添加透明颜色作为按钮和选择器作为背景来使其工作。但是我的解决方法并没有让我满意,您是如何解决这个问题的?你看的是什么文件?你怎么知道的,在文档中?
猜你喜欢
  • 2012-08-16
  • 1970-01-01
  • 2014-10-07
  • 1970-01-01
  • 2021-03-12
  • 1970-01-01
  • 1970-01-01
  • 2022-09-23
  • 1970-01-01
相关资源
最近更新 更多