我想将一个TextView的背景设置为50%透明度的白色(#ffffff
)。
我尝试使用android:alpha=0.5
,但它也会使文字变得50%透明。
我需要将白色背景设置为50%的透明度。
我找到了一个教程(链接),但没有完全理解。
请提供任何参考资料。 谢谢。
我想将一个TextView的背景设置为50%透明度的白色(#ffffff
)。
我尝试使用android:alpha=0.5
,但它也会使文字变得50%透明。
我需要将白色背景设置为50%的透明度。
我找到了一个教程(链接),但没有完全理解。
请提供任何参考资料。 谢谢。
在您的布局文件中,只需将TextView的背景设置为"#8FFF"即可。
<TextView
android:layout_width="..."
android:layout_height="..."
android:background="#8FFF"
/>
这里的 8 是 alpha 值,FFF 分别是 RGB 值。 点击此处查看有关 background 属性的更多信息
<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" />
你试过了吗:
textView.getBackground().setAlpha(range);
//其中0 < range <= 255,0表示透明,255表示不透明