首页 > TextView 如何设置半透明背景色?如图的效果。

TextView 如何设置半透明背景色?如图的效果。

如何 我想实现,字体下面的半透明背景, 不会遮住图片。 请问怎么处理呢?
我已经设置了如下的值( android:background="#e0000000"),但实现的效果, 确实黑色的背景,遮住了图片。

<TextView
        android:id="@+id/itemName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/app_name"
        android:textColor="@color/defaultWhite"
        android:textSize="16sp"
        android:background="#e0000000"
        android:layout_gravity="bottom" />
        
        

android:alpha="0.5"

参考 View.html#attr_android:alpha

alpha property of the view, as a value between 0 (completely transparent) and 1 (completely opaque).
Related Methods: setAlpha(float)

请善用developer.android.com


<TextView
...
background="#99000000"
style="@style/Transparent"
...
</TextView>

<style name="Transparent" parent="AppTheme">

    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:colorBackgroundCacheHint">@null</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowAnimationStyle">@null</item>
    <item name="android:windowNoTitle">true</item>

</style>

【热门文章】
【热门文章】