TextView和背景颜色

3

我想将我的textview背景颜色设置为透明的黑色。我该怎么做?


透明或黑色,因为透明的黑色没有意义 :) - ania
实际上,我需要类似对话框背景的浅黑色。这可行吗? - dilaraates
这可能会帮助您为TextView设置透明背景。 - android
2
你可以参考这个链接 <a href="https://dev59.com/P3I95IYBdhLWcg3wvgl9">Transparent</a> 这个链接对你有帮助。 - Dinesh Lingam
4个回答

8
android:background="#55000000"

如果您使用8位数字的颜色而不是6位数字,前两个数字将设置不透明度。在这种情况下,不透明度为0x55,即85/255 [大约33%的不透明度]。
对于编程方面,您可以使用以下代码(其中myTextView对应于您的视图):
myTextView.setBackgroundColor(0x55000000);

1
在我看来,这是唯一回答 OP 问题的帖子。 - Alexander Malakhov

3
 <?xml version="1.0" encoding="utf-8"?>
 <selector xmlns:android="http://schemas.android.com/apk/res/android">
 <item android:state_pressed="true" >
    <shape>
          <gradient 
            android:startColor="#2fDEDEDE"
            android:endColor="#2F000000"
            android:angle="270" />
        <stroke
            android:color="#cbc9c9" />

        <corners
            android:radius="3dp" /> 

        <padding
            android:left="5dp"
            android:top="5dp"
            android:right="5dp"
            android:bottom="5dp" />
    </shape>
</item>
<item>
    <shape>

            <gradient
            android:startColor="@android:color/transparent"
            android:endColor="@android:color/transparent"
            android:angle="270" />

            <stroke
            android:color="#c3c2c2" />

        <corners
            android:radius="4dp" /> 

        <padding
            android:left="5dp"
            android:top="5dp"
            android:right="5dp"
            android:bottom="5dp" />
    </shape>
</item>

用法: ==> android:background="@drawable/btn_trans"

如果您想设置黑色

android:background="#000"

0

将背景颜色设置如下

android:background="@android:color/transparent"

0

在Photoshop中使图像透明并将其应用于TextView背景...就这样,您已经为TextView获得了透明背景


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接