【问题标题】:How to make your TextView background transparent?如何使您的 TextView 背景透明?
【发布时间】:2019-07-10 01:10:47
【问题描述】:

我正在 Android Studio 中创建登录页面,但在构建项目时遇到了问题。

在一个教程中,显示​​包含#1100000 hexacode 将有助于使文本透明,它确实如此,但是当我构建程序时它给出了错误

error: '#1100000' is incompatible with attribute android:background (attr) reference|color.

我检查了一个说要添加 @android:color/transparent 的问题,但这并没有帮助。有什么建议吗?

<EditText
        android:id="@+id/editText"
        android:layout_width="200dp"
        android:layout_height="50dp"
        android:layout_below="@+id/textView2"
        android:layout_centerHorizontal="true"
        android:drawableLeft="@drawable/ic_action_pass"
        android:drawableStart="@drawable/ic_action_pass"
        android:ems="10"
        android:background="#1100000"
        android:hint="@string/password"
        android:inputType="textPassword"
        android:textSize="18sp" />

【问题讨论】:

  • 如果你用 alpha 属性检查它
  • 可能问题出在 android:drawableLeft="@drawable/ic_action_pass" 这一行。否则 @android:color/transparent 应该可以工作

标签: android xml kotlin


【解决方案1】:

试试这个

android:background="@null"

【讨论】:

  • dulu 指出,虽然问题很中肯,答案也很重要
【解决方案2】:
android:background="@android:color/transparent"

【讨论】:

  • 请阅读说明。我已经提到过没有帮助。
【解决方案3】:

您忘记了 0。#1100000 应该是 #11000000

该值始终以井号 (#) 字符开头,然后是 通过以下之一中的 Alpha-Red-Green-Blue 信息 格式:

  • #RGB
  • #ARGB
  • #RRGGBB
  • #AARRGGBB

https://developer.android.com/guide/topics/resources/more-resources#Color

Alpha 通道表示透明度值。 一些例子:

100% - FF
95% - F2
90% - E6
85% - D9
80% - CC
75% - BF
70% - B3
65% - A6
60% - 99
55% - 8C
50% - 80
45% - 73
40% - 66
35% - 59
30% - 4D
25% - 40
20% - 33
15% - 26
10% - 1A
5% - 0D
0% - 00

【讨论】:

  • 你好。谢谢你的评论,但我也试过了。当我构建程序时,它给出了同样的错误。
【解决方案4】:

尝试创建颜色值资源

&lt;color name="color_transparent"&gt;#00FFFFFF&lt;/color&gt;colors.xml values 目录下

然后将其用作文本视图中的背景:

android:background="@color/color_transparent"

通常,textviews 是透明的,所以请先检查父布局的属性。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-02
    • 1970-01-01
    • 2015-08-06
    • 2011-09-17
    • 2011-02-18
    • 2016-10-24
    • 2016-07-19
    相关资源
    最近更新 更多