【问题标题】:how to give transparency to button background in android如何在android中为按钮背景赋予透明度
【发布时间】:2014-05-08 05:31:56
【问题描述】:

我希望按钮在背景中具有一定程度的透明度。我正在使用

android:alpha="0.7"

为按钮提供透明度,但问题是按钮的文本也相应地褪色。我不希望按钮的文本褪色这是我的代码

xml 文件

<Button
                android:id="@+id/butbday"
                android:layout_width="fill_parent"
                android:layout_height="80dp"
                android:alpha="0.7"
                android:background="#0099CC"
                android:drawableLeft="@drawable/bday"
                android:paddingLeft="20dp"
                android:textStyle="bold" />

java 文件

String txtBday = "<big> <font color='#FFFFFF'>"
                + "Birthday & Anniversary" + "</font> </big>" + "<br />" 
                + "<small><font color='#FFFFFF'>" + "Invite all those who are ready for party today" + "</small>";

but_bday.setText(Html.fromHtml(txtBday));

【问题讨论】:

  • android:background="#800099CC", 开头 80 表示透明度为 50。
  • 将此 android:background="#0099CC" 更改为 android:background="#AA0099CC"。 :) 您可以尝试从 (00 - FF) 代替 AA 的各种选项。适合自己。
  • 为了防止混淆,十六进制的范围是 00 - FF(0 到 255)
  • 我的错。谢谢 :) 更正了自己。 :)

标签: android xml button


【解决方案1】:

试试这个:

<Button
        android:id="@+id/butbday"
        style="?android:attr/borderlessButtonStyle"   <! -- this does it for me -->
        android:layout_width="fill_parent"
        android:layout_height="80dp"
        android:background="#00000000"
        android:drawableLeft="@drawable/bday"
        android:paddingLeft="20dp"
        android:textStyle="bold" />

【讨论】:

    【解决方案2】:

    您可以使用 Alpha 通道创建十六进制颜色。要获得 0.7 alpha,请尝试 #B30099CC1#B3 = 179,大约是 255 的 70%)

    【讨论】:

      【解决方案3】:

      要在 Android 中提供透明度,只需在您的 # 代码开头相应地使用这些代码:

      例如使视图 50% 透明使用:

      android:background="#80000000"
      

      请注意开头的80

      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
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-02-22
        • 2014-02-13
        • 2015-06-10
        • 2014-06-20
        • 1970-01-01
        相关资源
        最近更新 更多