机器人的ImageButton得到灰色背景机器人、灰色、背景、ImageButton

2023-09-06 21:51:15 作者:り连空气都是爱你的形状

我有一个漂亮的背景选择一个按钮。精细。在按钮上的文字代替,我想要的图像。我已经试过它只是改变与src属性的ImageButton的。当我做到这一点,它看起来像一个灰色的背景上覆盖我的选择背后,在src形象背后。

i have a Button with a nice background selector. fine. in stead of text in the button, i want an image. i have tried just changing it to an ImageButton with a src attribute. when i do this, it looks like a gray background is overlaid behind my selector, behind the src image.

当我变回一个普通按钮,问题消失。我想要的只是我的背景选择,再加上SRC图像(在按钮上的文字代替)。

when i change back to a regular Button, the problem goes away. what i want is just my background selector, plus the src image (in stead of the button text).

什么想法?

推荐答案

的ImageButton应有的android:背景设定

ImageButton should have android:background set.

<ImageButton 
    android:id="@+id/ibArrow"
    android:layout_width="35px"
    android:layout_height="50px"
    android:src="@drawable/arrow"
    android:background="@drawable/backgroundstate" />   

和backgroundstate:

And backgroundstate:

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_selected="true" android:drawable="@color/transparent" />
        <item android:state_pressed="true" android:drawable="@color/transparent" />
    <item android:drawable="@color/transparent" />
   </selector>