Android 背景颜色设置为灰色而不是@android :color/white

标签 android layout colors background

在我的应用程序中,所有背景设置为 @background="@android:color/white" 的 View 都可以在除 Samsung Galaxy S3 mini 之外的所有设备上正确显示。在这种情况下,所有这些 View 都设置为灰色背景。

enter image description here

在此特定情况下,包含复选框的 LinearLayout 的背景应为白色:

<LinearLayout
                android:id="@+id/ll_child1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="@android:color/white"
                android:padding="10dp"
                android:orientation="vertical" >
...
</LinearLayout>

我尝试将 android:background="@android:color/white" 替换为 android:background="#FFFFFF",但唯一可行的解​​决方案是在我的 drawable 目录中创建一个 white_bg.xml:

<item android:bottom="0px">
    <shape android:shape="rectangle" >
        <solid android:color="@android:color/white" />
    </shape>
</item>

并将背景设置更改为 android:background="@drawable/white_bg"

虽然我认为这可以解决我的问题,但更改我的应用程序中的所有布局非常烦人,尤其是因为这个问题似乎只影响少数设备。我想知道是否有更优雅的解决方案。

最佳答案

更改 AppTheme 中的“windowBackground”:

在“styles.xml”中

<style name="AppTheme" parent="Theme.Holo">
    <item name="android:windowBackground">@color/white</item>
</style>

并从您的 LinearLayout 中删除背景属性。

当然要确保您的 Activity 使用 AppTheme 作为主题。 (同时将@color/white 值设置为“#ffffffff”)

关于Android 背景颜色设置为灰色而不是@android :color/white,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25204484/

相关文章:

android - 键盘打开时按钮与 EditText 重叠

layout - 更改 header.links 上的 'Create an Account' 文本?

c# - 如何在 Windows 窗体 C# 中为文本框提供渐变颜色

python - 在 pandas/matplotlib/seaborn python 中使用自定义配色方案

java - 如何将 'where' mySQL 查询转换为方法语法?

安卓 Wi-Fi 直连 : onPeersAvailable

java - Android: URL 以 -/\n 结尾的 TextView 链接错误

html - 水平对齐照片和文字时遇到问题

android - 为什么布局上的 setBackgroundColor 有时会使我的应用程序崩溃

javascript - WEBGL 改变颜色为三 Angular 形