XML设置View颜色不显示
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFF99"
android:layout_margin="20dp"
android:padding="60dp">
<view
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00FFFF" //设置颜色不显示
/>
</LinearLayout>
如果您在Android开发中设置了XML中的颜色,但是在实际运行中没有显示出来,可能是由于以下原因:
1、没有应用颜色
在XML文件中设置颜色后,必须在应用程序中使用该颜色。您可以在布局文件、主题文件、代码中或其他资源文件中使用该颜色。如果没有在应用程序中使用该颜色,那么该颜色将不会被显示出来。
2、颜色值设置不正确
在XML中设置颜色时,必须使用正确的颜色值格式。例如,如果您想设置红色,可以使用以下格式:
<color name="red">#FF0000</color>
如果颜色值的格式不正确,那么该颜色将不会被显示出来。
3、编译错误
如果您在XML文件中设置颜色后,重新编译应用程序时出现错误,那么该颜色将不会被显示出来。您可以检查编译日志,查找错误并解决它们。
如果以上方法都不能解决问题,您可以尝试清除应用程序的缓存和数据,然后重新启动应用程序。如果问题仍然存在,可能需要更多的调试和排查。
运行到手机或模拟器看看
<!-- animationOrder="normal"正常顺讯播放动画 -->
<!-- delay="0.5"递推是延时,效果为子view动画持续时间乘0.5 -->
<!-- animation="@anim/view_anim"设置使用子控件使用的动画文件,就是上文中的xml -->
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
android:animationOrder="normal"
android:delay="0.5"
android:animation="@anim/view_anim"/>
<!-- 直接通过layoutAnimation="@anim/layout_anim"设置动画 -->
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layoutAnimation="@anim/layout_anim"
android:layout_height="match_parent"/>
如果在XML文件中设置了View的颜色,但是在运行程序时发现颜色并没有显示出来,可能的原因如下:
解决方法如下: