简体   繁体   中英

(android) how to set background of TextView with black-transparent color

I want to set my background of LinearLayout and textview with black-transparent color so that the picture behind them can be seen well.

I tried with the code below, but it doesn't work

 <TextView
    android:id="@+id/text_feed_myPlant_comments"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="No Comments"
    android:textSize="22dp"
    android:layout_alignParentBottom="true"
    android:paddingLeft="10dp"
    android:background="@android:color/transparent"/> 

Try this

<TextView
android:id="@+id/text_feed_myPlant_comments"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="No Comments"
android:textSize="22dp"
android:layout_alignParentBottom="true"
android:paddingLeft="10dp"
android:background="#CCFFFFFF"/> 

You can change the transparency by changing first two character("CC") with below codes

100% — FF
95% — F2
90% — E6
85% — D9
80% — CC
75% — BF
70% — B3
65% — A6
60% — 99
55% — 8C
50% — 80
45% — 73
40% — 66
35% — 59
30% — 4D
25% — 40
20% — 33
15% — 26
10% — 1A
 5% — 0D
 0% — 00 

Try this;

Style.xml

<style name="Theme.Transparent" parent="android:Theme">
            <item name="android:windowIsTranslucent">true</item>
            <item name="android:windowBackground">@android:color/transparent</item>
            <item name="android:windowContentOverlay">@null</item>
            <item name="android:windowNoTitle">true</item>
            <item name="android:windowIsFloating">true</item>
            <item name="android:backgroundDimEnabled">false</item>
        </style>

Color.xml

<color name="transparent">#CCFFFFFF</color>

If you want change transparent Layout;

Layout.xml

     <activity android:name="com.ex.ex"
 android:theme="@style/Theme.Transparent">
</activity>

And Text View

<TextView
android:id="@+id/text_feed_myPlant_comments"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="No Comments"
android:textSize="22dp"
android:layout_alignParentBottom="true"
android:paddingLeft="10dp"
android:background="#CCFFFFFF"/>

Or you can use alpha

<TextView
android:id="@+id/text_feed_myPlant_comments"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="No Comments"
android:textSize="22dp"
android:alpha="0.5"
android:layout_alignParentBottom="true"
android:paddingLeft="10dp"
android:background="#FFFFFF"/> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM