Search code examples
androidfontsopacity

Dont want to pass opacity to font in android


I have taken one card view .applied black color to its background and i have taken text view and applied background image and passed opacity to textview for getting blackish image in output.but i don't want to apply opacity to the font on image.please help. Here is the code.

<android.support.v7.widget.CardView
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_gravity="center"
    android:layout_width="match_parent"
    android:layout_height="140dp"
    card_view:cardCornerRadius="10dp"
    android:layout_margin="15dp"
    card_view:cardElevation="20dp"
    android:textColorHighlight="@color/cardview_dark_background"
    app:cardBackgroundColor="#000000"
    >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="ICE CREAM WITH CRANBERRY SYRUP"
        android:textAlignment="center"
        android:textColor="#FFFFFF"
        android:alpha="0.5"
        android:background="@drawable/recp_one"
        />
</android.support.v7.widget.CardView>

enter image description here


Solution

  • Applying Image background for the Textview is not good in your case, Instead of that you can create ImageView and Textview different and apply what ever properties you need.

    it should look something like below.

    <android.support.v7.widget.CardView
            xmlns:card_view="http://schemas.android.com/apk/res-auto"
            android:layout_gravity="center"
            android:layout_width="match_parent"
            android:layout_height="140dp"
            card_view:cardCornerRadius="10dp"
            android:layout_margin="15dp"
            card_view:cardElevation="20dp"
            android:textColorHighlight="@color/cardview_dark_background"
            app:cardBackgroundColor="#000000"
            >
    
            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/recp_one"
                android:alpha="0.5"/>
    
            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="ICE CREAM WITH CRANBERRY SYRUP"
                android:textAlignment="center"
                android:textColor="#FFFFFF" />
    
    </android.support.v7.widget.CardView>