避免背景颜色混合android studio

时间:2021-05-17 12:41:53

标签: android-studio

如何避免子视图的背景颜色与其父视图的背景颜色混合? 第一张图片没有任何背景色(虽然默认是白色),第二张图片是浅橙色背景色。在其父视图的背景上应用橙色(浅色)后,子视图(即浅蓝色矩形)的背景发生了变化。first image without background color

second image with background color

以下是我的工作代码:- '''

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/list_item"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:minHeight="@dimen/listHeightMin"
    android:background="@color/listBg">

    <ImageView
        android:layout_width="@dimen/listHeightMin"
        android:layout_height="@dimen/listHeightMin"
        android:id="@+id/image"/>

    <LinearLayout
        android:id="@+id/textContainer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:background="@color/numberBg">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:gravity="bottom"
            android:layout_weight="1"
            android:id="@+id/english"
            android:textSize="20sp"
            android:layout_marginStart="16dp"
            android:textAppearance="?android:textAppearanceMedium"
            android:textColor="@color/white"
            android:textStyle="bold"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:gravity="top"
            android:layout_weight="1"
            android:id="@+id/hindi"
            android:textSize="20sp"
            android:layout_marginStart="16dp"
            android:textAppearance="?android:textAppearanceMedium"
            android:textColor="@color/white"
            android:textStyle="bold"/>

    </LinearLayout>

</LinearLayout>

'''

2 个答案:

答案 0 :(得分:1)

发生这种情况是因为您的浅蓝色矩形设置了不透明度。尝试添加纯十六进制颜色,而不是使用不透明度。

答案 1 :(得分:0)

您的背景颜色设置了不透明度。

不透明度从 00(完全透明)到 FF(不透明)。

在一个颜色中,有 4 个十六进制值:

  • 不透明度(此处为 B1)
  • 红色(此处为 C6)
  • 绿色(此处为 E2)
  • 蓝色(此处为 E3)

所以改变例如ERROR in compilation.fileDependencies.add is not a function

<color name="lightBlue">#B1C6E2E3</color>(或<color name="lightBlue">#FFC6E2E3</color>