1

我遇到了一个问题,即使用与我的资源之一不同的可绘制对象绘制 ImageButton 背景。我将背景设置为透明,但在某些情况下,它会拾取我的一个名为 bottom_shadow.9.png 的可绘制对象。为什么为什么!?真是太诡异了……

我以前见过这个问题......我的一些应用用户抱怨看到这个问题,现在我决心解决这个问题!下面看看我目前拥有的。任何提示或想法都会有所帮助。

我在 values/colors.xml 下创建的颜色值:

<color name="transparent">#00000000</color>

我在 layout/ 下的一个 xml 布局下的 ImageButton:

<ImageButton
    android:id="@+id/ibHelp"
    android:layout_width="wrap_content"
    android:layout_height="@dimen/settings_list_item_height"
    android:background="@color/transparent"
    android:contentDescription="@string/content_desc_more_information"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:scaleType="centerInside"
    android:src="@drawable/btn_help" />

这是我在生成的 R.java 文件中看到的:

public static final class drawable {
  public static final int bottom_shadow=0x7f020000;
}

public static final class color {
  public static final int transparent=0x7f080009;
}

这应该是这样的:

在此处输入图像描述

这就是我所看到的:

在此处输入图像描述

4

5 回答 5

2

会不会和这个问题有关?

http://code.google.com/p/android/issues/detail?id=20283

于 2012-02-08T22:41:05.770 回答
2

我认为您在另一个项目中面临与我相同的问题:在背景上使用透明颜色 #00000000 时,Android 实际上不会使其透明,而是使用其正下方元素的背景可绘制对象。

不确定我刚才说的是否清楚,但要检查是否是这样,我找到了一个快速简便的解决方案:不要使用 #00000000 作为背景透明,但任何其他完全透明的颜色:#00FF0000 甚至 #00F00000 都应该做。

请参阅我在 Google 跟踪器中提出的问题:http ://code.google.com/p/android/issues/detail?id=24653

于 2012-02-02T12:37:08.240 回答
1

Why are you creating your own color when it's built into Android.R.color? I would try using:

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

Whether or not it fixes your problem, it's simpler and cleaner.

于 2012-02-08T22:54:30.060 回答
0

我想你希望你的按钮的背景是某种颜色,但是你已经指定了按钮的 src 和颜色(在布局 xml 中),这意味着按钮可以使用 src 图片作为背景,而不是纯色。我不知道我是否说明了这一点。

于 2012-01-25T15:06:12.060 回答
0

除此之外,我在透明的 ImageButton 背景中看到了非常奇怪的周期性显示损坏,因为我在背景选择器中指定了如下项目:

<item android:drawable="@android:color/transparent" android:state_focused="false" android:state_pressed="false" android:state_selected="true"/>

似乎偶尔会起作用,但我肯定遇到过 ImageButtons 会以可怕的全白色背景而不是漂亮的透明背景呈现的情况。

请注意,我将 android:drawable 语法与颜色资源混合在一起。指定颜色资源的正确方法似乎是使用 android:color="#FF00FF" 属性或作为 item 的子元素使用元素。找了好久,终于找到了这个帖子。

于 2012-04-23T06:16:40.353 回答