Android 为什么我的ImageButton在其侧面保留空白图像的灰色?
我正在创建一个自定义标题栏,并在其中放置一些ImageButton,当您将ImageButton设置为默认值时,它只是灰色的。当您为其指定一个值时,它应该将其视图完全更改为该图像 出于某种奇怪的原因,我的想法是正确设置图像,但保留默认ImageButton的灰色边框。这有什么原因吗 下面是正在发生的事情的图片: 以下是标题栏的xml文件:Android 为什么我的ImageButton在其侧面保留空白图像的灰色?,android,imagebutton,titlebar,Android,Imagebutton,Titlebar,我正在创建一个自定义标题栏,并在其中放置一些ImageButton,当您将ImageButton设置为默认值时,它只是灰色的。当您为其指定一个值时,它应该将其视图完全更改为该图像 出于某种奇怪的原因,我的想法是正确设置图像,但保留默认ImageButton的灰色边框。这有什么原因吗 下面是正在发生的事情的图片: 以下是标题栏的xml文件: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="h
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_activity_flash_card_display"
android:textColor="@color/bluenessText" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageButton
android:id="@+id/flashCard_show_amount_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="right" />
</LinearLayout>
</LinearLayout>
您看到的灰色框实际上是背景。因此,当您设置ImageButton
drawable时,它设置的是图像,而不是背景。您可以使用imageButton.setBackgroundDrawable(null)
(或API 16+上的imageButton.setBackground(null)
,或者将背景设置为当前用于前景的任何可绘制图形。不幸的是,当我尝试更改背景颜色时,它没有更改。。。我尝试用setBackGroundColor更改它,setBackGroundDrawable被折旧,我只使用api 8,所以我不能使用setBackground,因为它的api 16编辑:我想我明白了。图像本身的边缘有一些白色,这可能就是我看到的。哈哈…谢谢!请记住,setBackgroundDrawable
仅在版本16+上不推荐使用。对于小于16的任何情况都可以使用它但我很高兴你解决了!