我在线性布局和卡片 View 中添加了背景图片。在 CardView 下,我添加了另一个渐变背景图像并设置了 alpha .5。当我添加 TextView 并添加文本时,文本也变得半透明,如图所示。我尝试使用粗体外观,但没有用。 I have uploaded the Image
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.vikramgehlot.QuotesandStatus.Apj"
android:background="@drawable/materialbackground" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="215dp"
android:orientation="vertical">
<ImageView
android:layout_marginTop="0dp"
android:layout_width="match_parent"
android:layout_height="215dp"
android:src="@drawable/ic_format_quote_black_24dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:layout_margin="10dp"
android:layout_width="350dp"
android:layout_height="70dp"
app:cardCornerRadius="40dp"
android:alpha=".5">
<LinearLayout
android:layout_margin="6dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/rectangle"
android:alpha=".5">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="fill"
android:text="Don’t let a mad world tell you that success is anything other than a successful present moment. "
android:textColor="@color/black"
android:textStyle="bold"
android:textSize="13dp"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
最佳答案
您可以为十六进制颜色赋予透明度。每个百分比的透明度都有一个唯一的代码,如更多详细信息所述here .
您可以在颜色文件中创建一种具有透明度的颜色并将其设置为卡片背景。例如:
<color name="semiTransparentColor">#40FFFFFF</color>
表示白色不透明度为 25%。
关于android - 设置 Cardview 形状和背景半透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50853117/