Android listview中的复选框样式不正确

Android listview中的复选框样式不正确,android,android-listview,android-styles,android-checkbox,Android,Android Listview,Android Styles,Android Checkbox,我在ListView中出现的复选框中的样式设置有问题。我的应用程序使用的主题是Holo,但复选框显示为旧样式。其他地方出现的复选框看起来不错。我不会做任何花哨的事情,比如创造我自己的风格。截图: 复选框应该与右图中的复选框相似。这是在v4.0.3上实现的。这些复选框看起来应该出现在我用v4.4.2尝试的另一台设备上 listview行的XML: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:andro

我在ListView中出现的复选框中的样式设置有问题。我的应用程序使用的主题是Holo,但复选框显示为旧样式。其他地方出现的复选框看起来不错。我不会做任何花哨的事情,比如创造我自己的风格。截图:

复选框应该与右图中的复选框相似。这是在v4.0.3上实现的。这些复选框看起来应该出现在我用v4.4.2尝试的另一台设备上

listview行的XML:

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

    <CheckBox android:id="@+id/ListRow_Task_TaskComplete" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:layout_marginLeft="6sp"
        android:focusable="false" />

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:paddingTop="7dip"
        android:paddingBottom="7dip"
        android:layout_toRightOf="@+id/ListRow_Task_TaskComplete"
        android:layout_centerVertical="true" >

        <TextView android:id="@+id/ListRow_Task_Name" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"
            android:textSize="16sp" />

        // next two textviews are programmatically hidden right now
        <TextView android:id="@+id/ListRow_Task_Deadline" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"
            android:text=""
            android:textSize="12sp" />

        <TextView android:id="@+id/ListRow_Task_Tags" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"
            android:drawableLeft="@drawable/icon_tag"
            android:drawablePadding="4dip"
            android:textSize="12sp" />  

    </LinearLayout>

</RelativeLayout>

//接下来的两个文本视图现在以编程方式隐藏

我怎样才能使左边的复选框看起来像应该的那样?

我也有这个问题。我正在使用三星Galaxy S4,我的应用程序中的复选框显示为老式。如果我在“Android Emulator”中运行相同的应用程序,它看起来就像我想要的那样


我的建议是最好的,别担心。只需在市场上传应用程序,就可以了

尝试将AndroidManifest.xml文件中的targetSdkVersion设置为最新版本(确保已下载该sdk版本):


从android drawable文件夹中复制所有DPI和分辨率的Holo复选框图像。然后将android:button属性设置为新的选择器xml。这样,您就可以完全控制它在目标设备上的外观

<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_checked="true" android:state_focused="true"
            android:drawable="@drawable/btn_check_on_focused_holo_light" /> 
    <item android:state_checked="false" android:state_focused="true"
            android:drawable="@drawable/btn_check_off_focused_holo_light" />
    <item android:state_checked="false"
            android:drawable="@drawable/btn_check_off_holo_light" />
    <item android:state_checked="true"
            android:drawable="@drawable/btn_check_on_holo_light" />
</selector>

我最近遇到了同样的问题,并找到了真正的解决方案,而不仅仅是解决办法

getView()
方法中膨胀视图时:

public View getView(int位置、视图转换视图、视图组父视图){
返回充气机。充气(R.layout.list_项,父项,false);
}

您需要确保您使用的充气器包含活动上下文而不是应用程序上下文,因为活动上下文知道您使用的主题,而应用程序不知道

因此,请确保按照以下或类似方式之一创建充气机:

  • layoutiner.from(活动)
  • getLayoutInflater();//来自活动内部
  • LayoutInflater.from(parent.getContext())
为了快速检查此解决方案,只需更换:

返回充气机。充气(R.layout.list\u项,父项,false)

与:


返回LayoutInflater.from(parent.getContext()).flate(R.layout.list_项,parent,false)

要在所有设备和所有版本中保持一致的外观和感觉,您必须如上所述对其进行定制。这似乎是最好的解决方案,尤其是考虑到@CRSardar的评论。谢谢你,你找到主要原因了吗?!我也有类似的问题,我只是想知道是哪部手机给你带来了麻烦。。三星Galaxy S4,也就是说,我不完全记得原因,甚至不知道我是否找到了答案。我只是使用了Holo的checkbox艺术的副本。抱歉…我使用的手机看起来不正确,它是Galaxy S2,正常工作的是Nexus 7。这实际上不是问题的根源,因为他在两个不同的设备上使用相同的清单尝试了相同的应用程序。。
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_checked="true" android:state_focused="true"
            android:drawable="@drawable/btn_check_on_focused_holo_light" /> 
    <item android:state_checked="false" android:state_focused="true"
            android:drawable="@drawable/btn_check_off_focused_holo_light" />
    <item android:state_checked="false"
            android:drawable="@drawable/btn_check_off_holo_light" />
    <item android:state_checked="true"
            android:drawable="@drawable/btn_check_on_holo_light" />
</selector>