android中给一个Button添加图片和文字的方法
来源:互联网 发布:web编程入门c# 编辑:程序博客网 时间:2024/06/07 08:22
//为按钮添加图片和文字的方法
public Spanned getSpan(int id, String s) {
ImageGetter imgGetter = new Html.ImageGetter() {
@Override
public Drawable getDrawable(String source) {
// TODO Auto-generated method stub
Drawable drawable = null;
drawable = MainActivity.this.getResources().getDrawable(
Integer.parseInt(source));
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight());
return drawable;
}
};
StringBuffer sb = new StringBuffer();
sb.append("<img src=\"").append(id).append("\"/>")
.append(" ").append("<font>" + s + "</font>");
;
Spanned span = Html.fromHtml(sb.toString(), imgGetter, null);
return span;
}
这个方法的使用:
button=(Button)findViewById(R.id.button);
button.setText(getSpan(R.drawable.button_iv,"按钮"));
其中 R.drawable.button_iv是int型的,存放在res/drawable文件夹下的图片,它是被添加到按钮上面的图片,它对应getSpan(int id,String s)中的id,而该方法中的s指的是添加到按钮上面的文字!
- android中给一个Button添加图片和文字的方法
- Android应用:Button添加图片和文字
- Button添加图片和文字
- android中给TextView或者Button的文字添加阴影效果
- android中给TextView或许Button的文字添加阴影效果
- Android在代码中添加一个Button的方法
- Android中ListView的item中添加图片和文字
- 给button和button上的文字添加按下效果
- android 中button上如何显示图片和文字
- Imagick添加文字和图片的方法
- 给图片添加透明文字水印的方法
- Android中给button添加响应事件的4种方法
- Android 含有图片和文字的Button的实现
- ios中交换button的图片和文字的位置
- ios中交换button的图片和文字的位置
- iOS中button 的图片和文字的位置
- Android实现自定义带文字和图片的Button
- Android实现自定义带文字和图片的Button
- android 系统定制的小技巧
- android:windowSoftInputMode属性使用
- android之Activity
- codeforces 15A. Cottage Village
- 网络编程(二)
- android中给一个Button添加图片和文字的方法
- ON_MESSAGE使用方法
- 零电阻的作用
- android adb调试桥
- Linux添加/删除用户和用户组
- jsp页面发送ajax请求实例
- Nginx负载均衡
- codeforces 320A. Magic Numbers
- CF 258E Little Elephant and Tree 【线段树,树上DFS序列】