缩小单选按钮图标

范思法兰

我正在开发一个Android应用程序,并使用它来自定义RadioButtons:

<!-- Radio button style -->
<style name="RadioButton" parent="@android:style/Widget.CompoundButton.RadioButton">
    <item name="android:button">@drawable/checkbox_unchecked</item>
</style>

但是图像@drawable/checkbox_unchecked很大。

您知道我如何缩小尺寸吗?

安吉·阿格瓦尔(Ankit Aggarwal)

我知道您可以通过减小图像大小来实现所需的功能但是我建议使用以下代码。这将帮助您设置选择模式选择模式的图像。

只需几个步骤,便可以实现此目的:-Image Drawables为它们的两个状态(选中/未选中)创建。-为这两个可绘制对象创建选择器。样本内容应该是这样的:

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

-将此选择器作为android:button属性添加到RadioButton

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

android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/background">

<RadioButton 
    android:id="@+id/radioButton1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:button="@drawable/checkbox_selector"
    android:text="Custom RadioButton" />

</LinearLayout>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章