Android使用xml定义带背景Button(解决ImageButton不能加文字的问题)
来源:互联网 发布:华为java技术面试题 编辑:程序博客网 时间:2024/05/18 03:18
虽然Android给我们提供了ImageButton 这一组件来实现带有自定义图片背景的Button,但是ImageButton有一个缺陷就是不能添加文字而如下的方法则可以综合二者的优势.
用到的图片:
在drable下新建一个button_blue_style.xml文件来描述Button的按下效果:
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/button_blue_click" /> <!-- pressed --> <item android:state_focused="true" android:drawable="@drawable/button_blue_click" /> <!-- focused --> <item android:drawable="@drawable/button_blue_nomal" /> <!-- default --></selector>
然后按照使用普通Button的方法在布局文件中加入该Button
<Button android:id="@+id/renrenButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/textView2" android:layout_centerHorizontal="true" android:background="@drawable/button_blue_style" android:drawableLeft="@drawable/renrenicon" android:text="@string/login_usingrenren" android:textColor="#000000" />需要说明的是为了使Button能够适应不同长度文字内容,我们使用.9PNG作为Button背景.
效果图如下:
- Android使用xml定义带背景Button(解决ImageButton不能加文字的问题)
- Android带文字的ImageButton实现
- Android带文字的ImageButton实现
- android--自定义带文字的ImageButton类
- Android带文字的ImageButton实现
- Android带文字的ImageButton实现
- 带文字的ImageButton
- Android的ImageButton不能显示文字
- Android中设置Button或者ImageButton的背景透明
- android 设置Button或者ImageButton的背景透明 半透明
- android 设置Button或者ImageButton的背景透明
- Android 设置Button或者ImageButton的背景透明 半透明 透明
- android 设置Button或者ImageButton的背景透明 半透明 透明
- android 设置Button或者ImageButton的背景透明 半透明 透明
- android 设置Button或者ImageButton的背景透明 半透明 透明
- android 设置Button或者ImageButton的背景透明 半透明 透明
- android 设置Button或者ImageButton的背景透明 半透明 透明
- android 设置Button或者ImageButton的背景透明 半透明 透明
- linux 文件映射
- 图论之搜索部分解题思路
- 序
- 不知道为什么在公司登陆不了csdn
- 从B 树、B+ 树、B* 树谈到R 树
- Android使用xml定义带背景Button(解决ImageButton不能加文字的问题)
- linux grep命令
- 让团队合作更紧密:SharePoint上的OneNote
- 开关和灯泡问题
- upnpx学习笔记
- VB中那些小控件---日期时间控件
- ubuntu实用工具
- AVR单片机通讯用发送标识UDRE和TXC的区别
- Windows下用Git下载android源码