android - 影响 Textview 颜色的父级相对布局前景色
问题描述
我需要一些透明的相对布局背景,因为我使用了渐变选项,但它也会影响文本视图颜色,我给文本视图的颜色是白色,但看起来像灰色。请帮助我摆脱这个问题。
<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>
解决方案
您可以使用#83000000
颜色代码来设置透明度,android:background
而不是android:background
属性。或者,您也可以使用"android:aplha="0.x"
where 1 < x < 9 来获得透明度。您的最终代码将如下所示。
<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
。
推荐阅读
- android - 构建项目时Android Studio中的AAPT错误
- javascript - 根据更改的属性数量创建对象数组
- android - 为什么是 todo-mvp-dagger,而不是 todo-mvvm-dagger?
- .net - IIS 上的 Web API - 内存消耗增加,直到应用程序池堆栈
- react-native - React Native 从 Mysql DB 获取新数据
- android - 当应用程序被用户或 Android 操作系统停止或杀死时,Android 应用程序未收到 Firebase 通知
- python - 未找到模块 - Plotly
- java - 如何从下面有线程内容的消息中获取最新的消息内容?
- javascript - 错误类型错误:无法读取 null 的属性“0”| 角 7
- ios - 核心蓝牙:CBPeripheral 在不知不觉中断开连接并且没有接到任何对 didDisconnectPeripheral 的调用