2014-04-21 23 views
0

我使用的是标准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> 

回答

2

要更改的属性是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" /> 
+0

感谢=现在尝试这个! – user3437721

+0

这工作,但由于某种原因,如果我点击我的列表行,复选框自定义选中的图像不会出现,直到我滚动屏幕“行”,然后当我回滚 - 它的存在。有任何想法吗?我添加了自定义复选框xml – user3437721

+0

这是用户按下自定义列表行时发生的情况:CheckBox cb =(CheckBox)view.findViewById(R.id.checkBox1); cb.performClick(); – user3437721

相关问题