Android的ImageButton当显示Drawable图片时就不显示文字
时间:2023-11-25 17:40:00
很多人对 Android提供的ImageButton有个疑问,当显示Drawable图片时就不会再显示文字了,其实解决的方法有三种:
第一种:就是图片中就写入文字,但是这样解决会增加程序体积,同时硬编码方式会影响多国语言的发布。
第二种:解决方法很简单,通过分析可以看到ImageButton的 layout,我们可以直接直接继承,添加一个TextView,对齐方式为右侧即可实现ImageButton支持文字右侧显示。
第三种:更简洁效率的方法:使用Button ,然后设定Button 的 android:drawableLeft 等属性即可。示例:
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/icon"
android:text="按钮"
/>
第四种:用布局多封一层
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/bt">
<ImageView
android:id="@+id/ib"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ringlove"
android:background="#00000000"
/>
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cs"
android:paddingLeft="20px"
/>
</LinearLayout>
标签:Android,ImageButton
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
快速解决设置Android 23.0以上版本对SD卡的读写权限无效的问题
2021-08-26 09:31:43
![](https://img.aspxhome.com/file/2023/2/117102_0s.jpg)
SpringBoot Pom文件依赖及Starter启动器详细介绍
2022-10-08 19:30:20
![](https://img.aspxhome.com/file/2023/7/80987_0s.png)
Jmeter常见函数使用方法汇总
2022-01-30 19:31:45
C#实现异步GET的方法
2022-08-17 11:52:55
Java中对List集合的常用操作详解
2023-05-02 23:52:47
Android 全屏无标题栏的三种实现方法
2022-01-05 03:01:31
java返回集合为null还是空集合及空集合的三种写法小结
2021-08-18 05:37:48
Java8处理集合的优雅姿势之Stream
2023-03-14 09:31:48
![](https://img.aspxhome.com/file/2023/0/119780_0s.jpg)
C#之WinForm跨线程访问控件实例
2023-11-20 19:05:13
Dubbo服务校验参数的解决方案
2023-06-09 14:30:10
![](https://img.aspxhome.com/file/2023/1/75751_0s.png)
SpringMVC使用MultipartResolver实现文件上传
2023-02-19 08:34:38
Intent传递对象之Serializable和Parcelable的区别
2022-05-27 04:02:42
轻松学习C#的方法
2023-06-21 13:22:32
![](https://img.aspxhome.com/file/2023/3/66573_0s.jpg)
详解spring cloud ouath2中的资源服务器
2022-09-24 15:36:43
![](https://img.aspxhome.com/file/2023/8/61238_0s.png)
Java网络编程之TCP程序设计
2023-10-29 15:53:32
java实现登录验证码功能
2021-06-08 19:34:18
![](https://img.aspxhome.com/file/2023/3/70953_0s.jpg)
java(包括springboot)读取resources下文件方式实现
2021-06-03 20:16:06
![](https://img.aspxhome.com/file/2023/4/68184_0s.png)
SpringBoot中的五种对静态资源的映射规则的实现
2023-06-21 08:31:47
![](https://img.aspxhome.com/file/2023/4/108354_0s.jpg)
Mybatis 如何开启控制台打印sql语句
2023-08-02 02:01:53
![](https://img.aspxhome.com/file/2023/5/99865_0s.jpg)
C# 创建高精度定时器的示例
2023-03-09 12:35:58
![](https://img.aspxhome.com/file/2023/4/76434_0s.png)