【问题标题】:Transparent background for button按钮的透明背景
【发布时间】:2015-09-26 19:57:27
【问题描述】:

我需要为我的按钮设置透明背景,但只有背景,而不是所有按钮。 我试过了:

android:background=""
android:background="null"

并且背景更改为透明,但出现错误:

Error: String types not allowed (at 'background' with value '').

【问题讨论】:

  • android:background="#AARRGGBB" 其中 AA 是您的 Alpha 通道。将此设置为 00 以使其透明。
  • 马特·克拉克 +1 , android:background ="#00000000"

标签: android button android-button android-attributes


【解决方案1】:

透明背景的材质波纹效果some Info

    android:background="?android:attr/selectableItemBackground"

例如

<Button
    android:layout_marginTop="15dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="?android:attr/selectableItemBackground"
    android:text="@string/add"
    android:layout_marginBottom="10dp"
    android:textSize="18sp"
    android:textStyle="bold"
    android:textColor="@color/fab_dark"
    android:id="@+id/btnOkFood"
    android:layout_gravity="right" />

在 appcompat v7 中,API => 11 支持此功能。它比透明背景好一点,只是因为提供了触摸反馈。

【讨论】:

  • 需要更高的 API 版本
  • 能否添加解释,例如文档链接?
【解决方案2】:

这个属性值的类型应该是颜色,所以使用内置属性来设置颜色值的透明背景:

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

【讨论】:

    【解决方案3】:

    您可以使用android:background="@null"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-05-20
      • 2015-02-22
      • 2014-12-19
      • 2020-04-08
      • 2014-02-13
      • 2014-01-04
      • 2016-08-02
      相关资源
      最近更新 更多