父相对布局前景颜色影响Textview颜色

时间:2019-01-30 09:55:42

标签: android

我需要渐变的相对布局背景,因为我使用了渐变选项,但是它也会影响文本视图的颜色,我给文本视图的颜色是白色,但看起来像灰色。请帮助我摆脱这个问题。

<RelativeLayout
    android:id="@+id/topLayout1"
    android:layout_width="match_parent"
    android:layout_height="210dp"
    android:layout_alignParentTop="true"
    android:foreground="@drawable/image_overlay"
    >

    <RelativeLayout
        android:id="@+id/topLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/preloader_image"
        >
        <TextView
            android:id="@+id/resName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="100dp"
            android:text="Green Way"
            android:textColor="@color/White"
            android:textSize="25sp"
            android:backgroundTint="@color/White"

            />

        <TextView
            android:id="@+id/desc"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/resName"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="5dp"
            android:text="@string/items"
            android:textColor="@color/White"
            android:textSize="16sp"
             />

    </RelativeLayout>
</RelativeLayout>

和图像叠加代码

 <?xml version="1.0" encoding="utf-8"?>
 <shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient
    android:startColor="#B0000000"
    android:centerColor="#A0000000"
    android:endColor="#00FFFFFF"
    android:angle="270"
    />
  </shape>

<color name="White">#FFFFFF</color>

1 个答案:

答案 0 :(得分:0)

您可以使用#83000000颜色代码设置透明度,也可以使用android:background而不是android:background属性来设置透明度。另外,您也可以使用"android:aplha="0.x"(其中1

<RelativeLayout android:id="@+id/topLayout1"
android:layout_width="match_parent"
android:layout_height="210dp"
android:layout_alignParentTop="true"
android:background="#83000000"
xmlns:android="http://schemas.android.com/apk/res/android">

<RelativeLayout
    android:id="@+id/topLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView
        android:id="@+id/resName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="100dp"
        android:text="Green Way"
        android:textColor="#FFFFFF"
        android:textSize="25sp"
        android:backgroundTint="#FFFFFF" />

    <TextView
        android:id="@+id/desc"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/resName"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="5dp"
        android:text="Items"
        android:textColor="#FFFFFF"
        android:textSize="16sp" />
</RelativeLayout>

您应该看到这个ANSWER了解更多关于透明度。您可以使用各种十六进制代码来实现不同程度的透明度。例如,对于50%的透明度,将使用80代码,而颜色代码将类似于#80000000。类似地,您可以在方案#xx000000中使用各种代码。