布局的背景颜色自动更改为白色

时间:2014-07-25 11:44:42

标签: android android-layout android-xml

我在我的应用程序的许多地方使用过这种颜色:#7A96A0。一切都很好看。但有时当我更改屏幕或滑动时,布局的背景颜色会自动更改为白色。这在我的整个应用程序中都会发生。它只发生在这种颜色上。这个颜色代码有问题。我已经给出了Xml文件中布局的背景知识。有人面临类似的问题。在此先感谢..

2 个答案:

答案 0 :(得分:1)

颜色代码没有问题,"#7a96a0"是有效的颜色代码。 我想你应该在strings.xml中的color属性中添加值和名称,然后在你的android xml中使用它。

go to res >> values >> strings.xml

然后添加

<color name="colour">#7a96a0</color>

在strings.xml中

之后转到xml文件并添加

<android:background="@color/colour">

您想要使用该颜色的任何地方。

希望这有帮助

答案 1 :(得分:0)

我在我的应用程序中遇到同样的问题 更改背景来源并将其链接到形状,如下所示:

形状:shape_sample.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
    <solid android:color="@android:color/white" />
</shape>

并在您的布局布局:my_layout.xml

<TextBox
   android:id="@+id/my_item_textView"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:background="@drawable/shape_sample" />

它对我有用,我希望对你有帮助。