[textview,白色背景的不透明度为50%

问题描述 投票:3回答:4

我正在尝试将#ffffff(白色)背景设置为TextView的不透明度为50%。我尝试使用android:alpha=0.5,但它也会使文本透明50%。

我需要在白色背景上设置50%不透明度。我找到了一个教程Here,但了解得不多。

请提供任何参考。提前致谢。

android background opacity
4个回答
16
投票

在布局文件中,只需将TextView的背景设置为“#8FFF”

<TextView
android:layout_width="..."
android:layout_height="..."
android:background="#8FFF"
/>

这里8是alpha值,FFF是RGB值。 See here for more info on the background attribute


3
投票

在您提到的教程中,您会注意到颜色值比您指定的值多两位数。您指定#FFFFFF(6位数字),而本教程指定#CCFF0000(8位数字)。相加的前两位(CC)表示字母。

因此,在您的情况下,请尝试类似#AAFFFFFF


0
投票

您尝试过:

textView.getBackground().setAlpha(range);

//其中0


0
投票

在白色背景上,textview的不透明度为50%:

    <TextView
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:alpha=".5"
     android:gravity="center"
     android:text="50% opacity"
     android:textColor="@color/white" />  

     OR

  <TextView
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:gravity="center"
     android:text="50% opacity"
     android:textColor="#80FFFFFF" />               
© www.soinside.com 2019 - 2024. All rights reserved.