如何去除按钮后面的边框?

36

我的应用程序按钮后面有一个灰色边框,我该如何去掉它?

我定义了这个ImageButton

<ImageButton
    android:id="@+id/btn_photo_lib"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:onClick="startPhotoLibAction"
    android:src="@drawable/library_blau_2" />

请确保您的背景没有边框。 - JoxTraex
4
尝试使用这个代码:android:background="@null",它的作用是将控件的背景设置为空。 - MAC
6个回答

95

您需要使用style="?android:attr/borderlessButtonStyle"

<ImageButton
    android:id="@+id/btn_photo_lib"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:onClick="startPhotoLibAction"
    android:src="@drawable/library_blau_2"
    style="?android:attr/borderlessButtonStyle"/>

1
如果我想更改背景颜色怎么办? - has19
1
@has19...你可以定义自己的定制样式,并将borderlessButtonStyle作为父级...<style name="blah" parent="borderlessButtonStyle"> - Johnny Wu

11

试一下这个:

<ImageButton
        android:id="@+id/btn_photo_lib"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="startPhotoLibAction"
        android:background="@android:color/transparent"
        android:src="@drawable/library_blau_2" />

11

简单易行的方法是

android:background="?android:attr/selectableItemBackground"

5
我发现这个方法非常有效:
android:background="@null"

4
只需将您的ImageView背景更改为透明,如下所示:
<ImageButton
    android:id="@+id/btn_photo_lib"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@android:color/transparent" <----- Set background.
    android:onClick="startPhotoLibAction"
    android:src="@drawable/library_blau_2" />

或者,您只需设置背景,然后无需应用透明颜色。

<ImageButton
    android:id="@+id/btn_photo_lib"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/download" <--- set only the background
    android:onClick="startPhotoLibAction"
 />

1

尝试在您的按钮选项卡中使用 style="?android:attr/borderlessButtonStyle"


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接