如何更改微调器复选框的大小或颜色?

13K*_*3KZ 5 android android-spinner

我正在开发一个Android项目,允许用户在警报对话框中选择项目列表(参见下图).

在此输入图像描述

我正在使用android.widget.spinner.但是复选框不是很明显.

我正在尝试个性化复选框,因为默认情况下这种类型.

那么可以用我自己的复选框替换它们吗?

Blu*_*ell 0

为自己创建一个可绘制的:

my_checkbox.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/my_checkbox_pressed" android:state_selected="true"/>
    <item android:drawable="@drawable/my_checkbox_focused" android:state_focused="true"/>
    <item android:drawable="@drawable/my_checkbox_pressed" android:state_pressed="true"/>
    <item android:drawable="@drawable/my_checkbox_default"/> <!-- pressed -->

</selector>
Run Code Online (Sandbox Code Playgroud)

这进去/drawable/

然后,您必须创建四个可绘制文件,这些将是 png 文件,您将需要为每种尺寸的屏幕(即/drawable-mdpi等)创建一个文件

您可以从 Android 源代码中获取这些内容,如果更容易的话,只需修改它们即可。(作为示例,请查看此处http://androiddrawableexplorer.appspot.com/并搜索复选框)

然后只需将其用作行项目布局的复选框

<CheckBox
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:button="@drawable/my_checkbox"
/>
Run Code Online (Sandbox Code Playgroud)

simple_spinner_item 看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@android:id/text1"
        style="?android:attr/spinnerItemStyle"
   android:singleLine="true"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:ellipsize="marquee" />
Run Code Online (Sandbox Code Playgroud)

您所要做的就是创建自己的布局文件,名为:

my_simple_spinner item.xml 将其放入drawable并添加您的自定义复选框:

<LinearLayout />
  <TextView />
  <CheckBox android:button="@drawable/my_checkbox" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

然后将其设置为每行的布局并自己处理复选框选择......这就是定制的价格。