2014-01-29 50 views
3

我有像这样的按钮...是否可以使按钮的背景透明?

enter image description here

很抱歉,如果它看起来暗,但你可以看到,我已经设置了高度和宽度来包装内容,但scaletype不fitxy所以如果你愿意,仍然是“按钮过剩”。

有什么方法可以删除它吗?

+0

使用'ImageButton'和它的背景设置为透明这样的:'机器人:背景=“@机器人:彩色/透明”' – Houcine

+0

实际上这是当你使用ImageButton作为src时的图像问题,你也会得到透明的图像。 –

回答

3

使用ImageButton和一套什么它的背景透明如下:android:background="@android:color/transparent"

<ImageButton 
     android:id="@+id/btn" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@android:color/transparent" 
     android:src="@drawable/btn_login" /> 
3

//是的,你可以用XML做通android:alpha

//在按钮属性添加此线下方,并改变你的阿尔法水平,只要你想

android:alpha="0.5" 
4

你可以使用ImageButton。这样做在你的XML

<ImageButton 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/imageButtonSettings" 
    android:src="@drawable/tabbar_icon" 
    android:background="@android:color/transparent"/> 

或编程。这是一个简单的只有你需要设置背景颜色为透明

ImageButton btn=(ImageButton)findViewById(R.id.ImageButton01); 
btn.setBackgroundColor(Color.TRANSPARENT); 
1

使用#0000(仅四个零,否则将被视为黑)这是透明的颜色代码。您可以直接使用它,但我建议您在color.xml中定义一种颜色,以便您可以重新使用代码。

+0

准确地说:在这些情况下,它将被视为**黑色**:#000,#f000,#000000和#ff000000 –

0

添加以下的属性到按钮标签

<button 
android:background="@android:color/transparent"/> 
+0

为什么投票下降? –