【问题标题】:50% opacity at white background for textviewtextview 的白色背景不透明度为 50%
【发布时间】:2013-12-15 22:28:13
【问题描述】:

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

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

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

【问题讨论】:

    标签: android background opacity


    【解决方案1】:

    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" />               
    

    【讨论】:

      【解决方案2】:

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

      所以在你的情况下尝试类似#AAFFFFFF

      【讨论】:

        【解决方案3】:

        在您的布局文件中,只需将 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

        【讨论】:

        • 但是你是如何计算这个的......我没有从你的链接中得到......你的答案是正确的......但需要理解......你计算这个?......可以详细说明?
        • 这些值是十六进制值。您可以认为每个值分别独立于 A、R、G、B 值。十六进制数字是基数 16,16 的一半是 8。因此是 8。
        • 那么在 50% 不透明度 (#0000000) 下黑色的值是多少?我只需要清除我的知识。
        • 将十六进制值转换为整数值并除以 255 得到百分比。所以最大的十六进制值 (FF=255) 减半是 80=128,所以你的整个答案是 #80000000。
        【解决方案4】:

        你试过了吗:

        textView.getBackground().setAlpha(range);
        

        //其中0

        【讨论】:

          猜你喜欢
          • 2012-02-22
          • 2014-08-21
          • 2021-02-01
          • 1970-01-01
          • 1970-01-01
          • 2013-04-03
          • 2023-03-15
          • 2021-03-24
          • 2013-11-27
          相关资源
          最近更新 更多