android - 设置 Cardview 形状和背景半透明

标签 android android-layout android-fragments

我在线性布局和卡片 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/

相关文章:

android - 我想在触摸点的关系布局上添加动态 ImageView

android - android :gravity in attrs. xml 的正确格式?

java - 我不断收到数据绑定(bind)错误,但不确定原因或如何修复它

java - 无法在 fragment 中使用适配器显示 ListView

android - TabLayout 和底部导航

android - 现在无法访问dex任务,如何升级到1.5.0?

android - 如何在不root手机的情况下访问其他应用程序的/data/data目录

android - 为科学计算器创建一个按钮

android - 当我尝试编辑 EditText 的文本时,如何防止 ArrayAdapter getView() 重复调用?

android - 使用 NavigationDrawer 切换时如何只保留 fragment 的一个实例?