自定义复选框图像-但仍然可以看到原始图像



我使用的是标准的Android复选框,但当我在其他人的手机上安装应用程序进行测试时,每个手机上的复选框都不同。

在其中一部手机上,复选框很亮,当你选中复选框时,你几乎看不到它。

所以我尝试制作一个自定义复选框选中的图像。

这还可以,但我仍然可以在背景中看到原始的deafult复选框图像?

有什么想法吗?

这是我的可检查线性布局,老实说,我甚至不确定我是否需要这个?

<?xml version="1.0" encoding="utf-8"?>
<com.myapp.myappname.CheckableLinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >
    <CheckBox
        android:id="@+id/checkBox1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="CheckBox"
        android:background="@drawable/customcheckbox"/>
    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView" />
    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
         />
</com.myapp.myappname.CheckableLinearLayout>

然后我有一个自定义列表行,它是我的自定义ListView:

<?xml version="1.0" encoding="utf-8"?>
<com.myapp.myappname.CheckableLinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:padding="5dip" >
    <!--  Thumbnail image -->
    <LinearLayout android:id="@+id/thumbnail"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="3dip"
        android:layout_alignParentLeft="true"
        android:layout_marginRight="5dip">
        <ImageView
            android:id="@+id/list_image"
            android:layout_width="60dip"
            android:layout_height="60dip"
            android:focusable="false"
            />
    </LinearLayout>
 <!-- File Name -->
    <TextView
        android:id="@+id/filename"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/title"
        android:textColor="#343434"
        android:textSize="12dip"
        android:layout_marginTop="10dip"
        android:layout_toRightOf="@+id/thumbnail"
        android:focusable="false"
        android:text="Some Text." />
    <CheckBox
        android:id="@+id/checkBox1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:focusable="false"
        android:layout_alignParentRight="true"
        android:background="@drawable/customcheckbox"
        android:enabled="false" />
</RelativeLayout>
 </com.myapp.myappname.CheckableLinearLayout>

有什么想法可以压制原作吗?

自定义复选框:

<selector  xmlns:android="http://schemas.android.com/apk/res/android">
    <!--<item android:state_checked="false" android:drawable="@drawable/unchecked" />-->
    <item android:state_checked="true" android:drawable="@drawable/checked" />
    <!--<item android:drawable="@drawable/unchecked" /> &lt;!&ndash; default &ndash;&gt;-->
</selector>
要更改的属性是button,而不是background

首先,为不同的按钮状态设计自定义图形。使用状态列表可绘制(docs)来关联各种图像。例如:

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

将其保存到可提取资源文件夹中,类似于my_checkbox.xml。

现在,使用复选框布局定义上的按钮属性:

<CheckBox
    android:id="@+id/checkBox1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:focusable="false"
    android:layout_alignParentRight="true"
    android:button="@drawable/my_checkbox"
    android:enabled="false" />

最新更新