如何拥有透明的ImageButton:Android

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:src="@drawable/media_skip_backward"

android:background="@drawable/transparent">

这就是我试图获得透明的ImageButton以便将这些按钮放在SurfaceView上。 但是,只要我在xml中包含透明线,Eclipse就会在项目中出现错误。

请帮忙。

17个解决方案

907 votes

尝试使用null作为背景...

android:background="@null"

Quintin Robinson answered 2019-03-29T19:14:41Z

258 votes

不要使用TRANSAPENT或NULL布局,因为按钮(或通用视图)将不会在点击时突出显示!

我遇到了同样的问题,最后我从Android API找到了正确的属性来解决问题。 它可以应用于任何视图。

在按钮规格中使用它:

android:background="?android:selectableItemBackground"

lory105 answered 2019-03-29T19:15:18Z

132 votes

您还可以使用透明色:

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

Geykel answered 2019-03-29T19:15:41Z

104 votes

将背景设置为"@null"将使按钮在单击时无效。 这将是一个更好的选择。

style="?android:attr/borderlessButtonStyle"

后来我发现使用了

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

也是一个很好的解决方案。 并且您可以以自己的样式继承此属性。

Eliko answered 2019-03-29T19:16:18Z

14 votes

在运行时,您可以使用以下代码

btn.setBackgroundDrawable(null);

Adem answered 2019-03-29T19:16:42Z

10 votes

我相信接受的答案应该是:android:

这与@ lory105的答案相同,但它使用支持库以实现最大兼容性(android:等效仅适用于API> = 11)

Sam Stern answered 2019-03-29T19:17:14Z

7 votes

删除此行:

android:background="@drawable/transparent">

并在您的活动类集中

ImageButton btn = (ImageButton)findViewById(R.id.previous);

btn.setAlpha(100);

您可以将alpha级别设置为0到255

o表示透明,255表示不透明。

Nishant Shah answered 2019-03-29T19:18:08Z

5 votes

最好的方法是使用透明色码

android:background="#00000000"

使用颜色代码#00000000使任何事物透明

Ajay Venugopal answered 2019-03-29T19:18:39Z

1 votes

只需在.java文件中使用此代码:

ImageButton btn = (ImageButton) findViewById(R.id.ImageButton01);

btn.setBackgroundColor(Color.TRANSPARENT);

emi raza siddique answered 2019-03-29T19:19:08Z

1 votes

在XML中将ImageButton的背景设置为@null

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:src="@drawable/media_skip_backward"

android:background="@null">

Murtuza Khan answered 2019-03-29T19:19:36Z

1 votes

使用“@null”。 它对我有用。

android:layout_width="wrap_content"

android:layout_height="wrap_content"

app:srcCompat="@drawable/bkash"

android:id="@+id/bid1"

android:layout_alignParentTop="true"

android:layout_alignParentLeft="true"

android:layout_alignParentStart="true"

android:background="@null" />

abir99 answered 2019-03-29T19:20:15Z

1 votes

使用ImageView ...默认情况下它具有透明背景......

Caipivara answered 2019-03-29T19:20:41Z

0 votes

这是以编程方式设置的背景颜色为透明

ImageButton btn=(ImageButton)findViewById(R.id.ImageButton01);

btn.setBackgroundColor(Color.TRANSPARENT);

Xar E Ahmer answered 2019-03-29T19:21:06Z

0 votes

以编程方式可以通过以下方式完成:

image_button.setAlpha(0f) // to make it full transparent

image_button.setAlpha(0.5f) // to make it half transparent

image_button.setAlpha(0.6f) // to make it (40%) transparent

image_button.setAlpha(1f) // to make it opaque

Muhammed Refaat answered 2019-03-29T19:21:30Z

0 votes

在您的XML集Background属性为任意颜色White(#FFFFFF) shade或Black(#000000) shade.if您希望透明度只是在实际哈希代码之前放80。

#80000000

Alireza Ghanbarinia answered 2019-03-29T19:21:55Z

0 votes

用这个:

android:id="@+id/back"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="@null"

android:padding="10dp"

android:src="@drawable/backbtn" />

Akshay Paliwal answered 2019-03-29T19:22:15Z

-2 votes

android:id="@+id/previous"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="@drawable/media_skip_backward">

我使用透明png作为ImageButton,而ImageButton工作。

Kiyoshi answered 2019-03-29T19:22:41Z

android如何添加透明图片按钮,如何拥有透明的ImageButton:Android相关推荐

  1. 怎样在android中添加背景图片?

    怎样在android中添加背景图片? 1.打开左侧的工程文件夹.打开res中的layout,双击main.xml. 2.一般的图片是jpg格式的,要把格式转化为png格式的. 3.把PNG格式的图片拖 ...

  2. Android(Kotlin)图片按钮,单选框,复选框(实验课)

    Android的一次"实验课布置的内容" 里面有一些可以擦考的东西 所以借着CSDN来记个笔记 其实也没啥 第一次写 留个纪念 图片按钮,单选框,复选框(话不多说上代码) butt ...

  3. html5透明图片格式,支持png透明图片解决方法图

    一.需求JS文件赞成 1.需要DD_belatedPNG.js与DD_belatedPNG_0.0.8a.js文件,下面咱们会供给打包下载 2.紧要在需求赞成png图片html页面引入这2个JS文件( ...

  4. android相机添加一层图片,android 在照片上加标签(贴纸标签相机)源码

    [实例简介]功能:拍照,相片裁剪,给图片贴贴纸,打标签 实现相机功能 实现对图片进行裁剪的功能 图片的滤镜功能 能为图片添加贴纸(贴纸可移动,放大,旋转) 能为图片添加标签(同样可以移动) 本地保存制 ...

  5. python tkinter button 透明图片_Tkinter-按钮图像透明背景

    据我所知,tkinter本机支持像GIF这样的图像的透明性. 我把你的代码切碎了一点,但对我确实有用.也许你设置代码的方式有问题.你的标签上还有一个按钮.我觉得你不需要两者都有.你可以在你想要的地方创 ...

  6. 【为您的 Android 应用添加图片】

    上一篇:[创建 Birthday Card 应用] 一.简介 在本文章中,您将学习如何使用 ImageView 向应用添加图片. 前提条件 了解如何在 Android Studio 中创建和运行新应用 ...

  7. 界面组件——按钮(Button)与图片按钮(ImageButton)

    介绍 用例 介绍 Button继承了TextView,同时还是ImageButton的父类. Button.ImageButton的功能主要是在UI界面上生成一个按钮,该按钮可以供用户单击,当用户单击 ...

  8. Android studio实现多个按钮跳转多个页面

    Android studio实现多个按钮跳转多个页面 Android studio通过多个按钮实现多个页面的跳转 要求下一个页面有音频.图片.单选按钮(RadioGroup)和复选框(CheckBox ...

  9. CxImage透明图片合成和文字叠加

    1         CxImage的作用 CxImage将几张图片合成一张图片,在一张底图上添加图片,有些图片是有透明效果的,实现图片之间的透明重叠效果.另外还可以添加文字. (1)背景图片mymix ...

最新文章

  1. 小伙在某知名公司的Python面试题详解,希望对各位以后面试有帮助
  2. unity android eclipse,[转]Android笔记:Eclipse嵌入Unity3D开发的3D场景
  3. 网站排名和权重骤降的原因是什么?又该如何处理?
  4. 点击cell动态修改高度动画
  5. FreeMarker 一二事 - 静态模板的使用与生成
  6. mysql 授权访问_windows开启3306端口并用可视化工具访问远程mysql(授权访问)
  7. 今天我不想发文了,对不起各位!
  8. hdu 2184 01背包变形
  9. 从Qt Console Application到Qt GUI Application
  10. android设计个人简历页面_Android程序员简历模板
  11. Linux查看硬盘挂载
  12. oracle磁盘满了怎么办,ORACLE磁盘空间占满解决
  13. 房价必然上涨的N个原因
  14. 打造Win10+WSL开发环境(2)
  15. python3 输入数字_python怎么输入数字
  16. navicat导入excel 日期格式处理
  17. 电脑打开“我的电脑”、“资源管理器”很慢的解决办法。
  18. 鼠标作为画笔 | 八
  19. Hash(散列)冲突解决之线性探测再散列和二次探测再散列
  20. 基于FPGA的信号发生器

热门文章

  1. 教育知识与能力——简答题30题
  2. 糟糕!服务器被植入挖矿木马,CPU飙升200%
  3. Apache Commons Lang3 DateUtils用法
  4. ERNIE3.0多分类任务应用详细教程代码
  5. OSChina 周四乱弹 ——心有鱼,而力不足
  6. 当厌氧菌遇见氧气之后,氧毒性、耐受性和防御性机制
  7. 比较器翻转抖动原因及对策
  8. React 教程及其API接口文档
  9. 基于视频点播上传、多分辨率转码-搭建自己的短视频|教学视频播放系统
  10. 分享一个DEM数据下载的方法