【问题标题】:Transparent color resource displays as red gradient in Android透明颜色资源在Android中显示为红色渐变
【发布时间】:2012-06-21 12:49:05
【问题描述】:

我在使用 Android 中的颜色资源时遇到问题,特别是使用透明颜色。

每当我使用颜色资源中的透明颜色时,在模拟器(在 AVD 上测试版本 1.6、2.2 和 2.3)或设备(DroidX w / 2.3.4)。在 Eclipse 的预览模式中,透明色显示正确(或者说不正确)。

据我所知,这个特定的渐变在我的应用程序的任何地方都没有定义。标题栏确实使用了来自 xml 形状资源的红色渐变,但它是完全不同的红色阴影。还有一个很简单的自定义样式定义,不过只是设置了窗口标题背景和文字颜色。

我的颜色定义:

<color name="transparent">#0000</color>  <!--Tried #00000000 as well // -->

展示问题的示例视图:

<Button
    android:id="@+id/btn_login"
    android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="5dp" android:layout_marginRight="10dp"
    android:text="@string/ui_btn_login" android:textColor="@color/dark_grey"
    android:background="@color/transparent"
    android:drawableTop="@drawable/ic_login" android:drawablePadding="2dp" />

导致红色渐变(使用颜色资源时): http://i683.photobucket.com/albums/vv194/platinumF150/trans_resource.png

<Button
    android:id="@+id/btn_login"
    android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="5dp" android:layout_marginRight="10dp"
    android:text="@string/ui_btn_login" android:textColor="@color/dark_grey"
    android:background="#0000"
    android:drawableTop="@drawable/ic_login" android:drawablePadding="2dp" />

导致正确显示(使用内联颜色代码时): http://i683.photobucket.com/albums/vv194/platinumF150/trans_color.png

但是,当我使用 android:background="@android:color/transparent" 时,一切正常...

我在整个应用程序中都看到了这种情况,任何使用 @color/transparent 的视图都会变成红色渐变。

显然,在任何地方都使用 Android 的透明颜色并不是什么大不了的事,它只是令人沮丧,我相信有一个解决方案。我以前从未见过这个问题,但我也从未在应用中使用过多的透明度。

感谢您的任何想法或意见!

【问题讨论】:

  • 使用@android:color/transparent 从透明颜色
  • 这解决了问题,但是,我想知道为什么?因为它也可能是其他颜色的问题(即半透明)。

标签: android android-layout android-resources


【解决方案1】:

根据

android.R.color.transparent not fully transparent

&

How to make a ListView transparent in Android?

“#00000000”应该可以工作............

使用透明色中的@android:color/transparent 而不是android:background="@color/transparent"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多