android - 是否可以使按钮的背景透明?

标签 android image

我有一个这样的按钮...

enter image description here

抱歉,如果它看起来很暗,但如您所见,我已经设置了高度和宽度来包裹内容,但 scaletype 不是 fitxy,所以如果您愿意的话,仍然存在“按钮过多”。

有什么办法可以去掉吗?

最佳答案

您可以使用 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);

关于android - 是否可以使按钮的背景透明?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21427343/

相关文章:

android mailto 代码无法正常运行

android - Kotlin Android 中的错误 "unresolved reference"

android - 无法解析 org.webkit :android-jsc:+

java - ANDROID:获取按钮 XML Id

php - 如何从 base64 编码的 jpeg 创建 GD 图像?

image - 如何保存以 Data-URI 编码的图像?

javascript - 使用 src=require() 时来自 webpack 的 Vue.js 错误 "Cannot find module ' ./undefined'"

android - 当 Activity 被破坏时,GPS图标不会消失吗?

c# - C# 中的类无法识别 System.Drawing 中的图像类

image - 当图像(来自react-native)抛出 onError 时渲染文本组件