有什么方法可以从ImageButtons中删除灰色背景?

时间:2012-03-02 02:48:35

标签: android eclipse

我有一个ImageButton,我想删除围绕Image的丑陋(恕我直言)背景。我可以添加一个ImageView,但是它们很难在布局中完美地设置,就像图中的灰色一样。 [重力“中心”不会使它向中间移动,只是垂直居中。)

那么删除它的方法是什么?

enter image description here

10 个答案:

答案 0 :(得分:34)

只需使用android:background="#0000" (#0000与#00000000相同) 或

ImageButton imageButton = new ImageButton(this);
imageButton.setBackgroundDrawable(null);

答案 1 :(得分:23)

默认背景不透明。

所以,只需添加透明色“#00000000”作为背景,然后就可以解决了。

P.S。 #00000000是透明色

<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon" 
android:background="#00000000"
/>

答案 2 :(得分:3)

只需在xml中使用android:background="@null"

答案 3 :(得分:2)

你可以保留方框,只需改变它的颜色:

android:backgroundTint="@color/colorPrimary"

工作得很漂亮

答案 4 :(得分:0)

如果你设置

android:background 

而不是

android:src 

它应该覆盖灰色背景

答案 5 :(得分:0)

呀。如果你拖动通常会要求ImageSource的ImageButton。但ImageSource(android:src)并没有删除灰色背景。这是一张应该在背景之上的图像:

而不是在布局XML中尝试android:background。

答案 6 :(得分:0)

请使用Draw 9-patch格式为图像b'使用它由SDK提供

1. From a terminal, launch the draw9patch application from your SDK /tools directory.
2. Drag your PNG image into the Draw 9-patch window (or File > Open 9-patch... to locate  the file). Your workspace will now open.

左侧窗格是您的绘图区域,您可以在其中编辑可伸展的色块和内容区域的线条。右侧窗格是预览区域,您可以在拉伸时预览图形。

3. Click within the 1-pixel perimeter to draw the lines that define the stretchable patches and (optional) content area. Right-click (or hold Shift and click, on Mac) to erase previously drawn lines.

4. When done, select File > Save 9-patch...

您的图片将以.9.png文件名保存。

答案 7 :(得分:0)

像这样使用

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

android:src="@drawable/icon"

答案 8 :(得分:0)

我遇到了同样的问题,但现在已经解决了。如果您使用的是“android:background =”@ null“,则根本没有任何背景,并且不会向用户显示按钮按下的动画。

只需添加此行代码,即可在单击时使图像按钮闪烁。这是提醒用户点击图像按钮的正确方法。

angular.module('myApp', [])

.controller('AppCtrl', [function() {
    var ctrl = this;

    ctrl.data = { name: "Han Solo" };

    ctrl.welcomeMessage = 'Welcome to Angular';
}])

.directive('outer', function(){
    return {
        restrict: 'E',
        transclude: true,
        scope: {
            model: '='
        },
        template: '<div class="outer"><inner my-data="model"><div ng-transclude></div></div></div>'
    };
})

.directive('inner', function(){
    return {
        restrict: 'E',
        transclude: true,
        scope: {
            source: '=myData'
        },
        template :'<div class="inner" my-transclude></div>'
    };
})

.directive('myTransclude', function() {
    return {
        restrict: 'A',
        transclude: 'element',
        link: function(scope, element, attrs, controller, transclude) {
            transclude(scope, function(clone) {
                element.after(clone);
            })
        }
    }
});

答案 9 :(得分:0)

所有建议的解决方案都可以消除波纹动画(点击)

将背景色模式设置为“添加”将删除背景并保留波纹动画:

tsc
相关问题