【问题标题】:How to change the size of the button of an android checkbox?如何更改android复选框按钮的大小?
【发布时间】:2012-04-26 19:14:59
【问题描述】:

我更改了 Android 2.3.4 复选框的位图,并希望设置位图的大小以缩放它们。我像这样更改了复选框:

<CheckBox
    android:id="@+id/cb1"
    android:button="@drawable/checkbox"
    android:layout_alignParentLeft="true"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Sort: 1" />

使用匹配的 xml 可绘制对象

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true"  android:state_focused="true"    android:drawable="@drawable/checkbox_on_background_focus_yellow"/>
    <item android:state_checked="false" android:state_focused="true"    android:drawable="@drawable/checkbox_off_background_focus_yellow"/>
    <item android:state_checked="false" android:drawable="@drawable/checkbox_off_background" />
    <item android:state_checked="true"  android:drawable="@drawable/checkbox_on_background" />
</selector>

如何设置 dip/dp 值来更改复选框位图的大小?

【问题讨论】:

标签: java android checkbox bitmap


【解决方案1】:

只需定义相关的 Drawable 并将它们设置到您的复选框属性中。

android:background="@drawable/my_background"

【讨论】:

  • 我不明白你的意思,你能不能再准确一点?
【解决方案2】:

我通过使位图大小合适来解决这个问题。我现在无法缩放它,但我在几台具有不同 dpi 设置的设备上对其进行了测试,看起来还不错。暂时。

【讨论】:

    【解决方案3】:

    实际上,将图像设置为复选框大小的方法是放置

    android:button="@null"
    android:background="@drawable/checkbox" <!-- your custom selector -->
    

    这样,您的自定义复选框图像(在两种状态下,选中和未选中)将始终适合您的复选框大小。

    【讨论】:

    • 还有android:backgroundTint="@color/checkbox_selector"
    猜你喜欢
    • 2016-08-07
    • 1970-01-01
    • 1970-01-01
    • 2016-09-25
    • 1970-01-01
    • 2012-02-05
    • 1970-01-01
    • 1970-01-01
    • 2014-05-09
    相关资源
    最近更新 更多