Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android复选框自定义图像未正确显示_Android - Fatal编程技术网

Android复选框自定义图像未正确显示

Android复选框自定义图像未正确显示,android,Android,在我的项目中,我有一个复选框,我正在尝试为选中和未选中状态添加一个自定义图像,但是这些图像在xhdpi屏幕上没有正确显示。请提供帮助 我正在发布xml和屏幕截图 自定义复选框.xml check_box.xml 您应该为按钮属性使用自定义xml文件 <CheckBox android:id="@+id/chkVibrate" android:layout_width="wrap_content" android:layout_height="wrap_c

在我的项目中,我有一个复选框,我正在尝试为选中和未选中状态添加一个自定义图像,但是这些图像在xhdpi屏幕上没有正确显示。请提供帮助

我正在发布xml和屏幕截图

自定义复选框.xml

check_box.xml


您应该为按钮属性使用自定义xml文件

 <CheckBox
    android:id="@+id/chkVibrate"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:button="@drawable/custom_checkbox"
    android:text="CheckBox Text"
    android:textColor="@color/white" />

如果要在不同的聚焦状态下设置不同的图像,也可以通过这种方式创建自定义文件

<?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/ic_check"
    android:state_focused="false">
</item>
<item android:state_checked="true" 
    android:drawable="@drawable/ic_check"
    android:state_focused="true">
</item>
<item android:state_checked="false" 
    android:drawable="@drawable/ic_uncheck"
    android:state_focused="false">
</item>
<item android:state_checked="false" 
    android:drawable="@drawable/ic_uncheck"
    android:state_focused="true">
</item>
</selector>


这里有什么问题?两张照片都很好看same@VaibhavAgarwal现在请检查并确保在
可绘制hdpi
可绘制xhdpi
文件夹中有相应的图像。@SMR Ya我也有bot-imagesplz粘贴xml文件的复选框。不起作用,我在询问图像和文本之间的间距。将填充设置为您的复选框,然后尝试android:padding=“10dp”看到的是,在hdpi屏幕中,空间会自动显示,如果我设置填充,在xhdpi中,空间会起作用,但在hdpi中,默认空间会被修剪,如果我在xhdpi屏幕中将其设置为20dp,则空间会过大。
 <CheckBox
    android:id="@+id/chkVibrate"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:button="@drawable/custom_checkbox"
    android:text="CheckBox Text"
    android:textColor="@color/white" />
<?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/ic_check"
    android:state_focused="false">
</item>
<item android:state_checked="true" 
    android:drawable="@drawable/ic_check"
    android:state_focused="true">
</item>
<item android:state_checked="false" 
    android:drawable="@drawable/ic_uncheck"
    android:state_focused="false">
</item>
<item android:state_checked="false" 
    android:drawable="@drawable/ic_uncheck"
    android:state_focused="true">
</item>
</selector>