定义圆角矩形背景
2012-05-16 15:50
169 查看
XML文件 res/drawable/my_rounded_rectangle.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#f0600000"/>
<stroke android:width="3dp" android:color="#ffff8080"/>
<corners android:radius="5dp"/>
<padding android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp"/>
</shape>
在Java中使用图像
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
GradientDrawable roundedRectangle=(GradientDrawable) this.getResources().getDrawable(R.drawable.my_rounded_rectangle);
TextView tv=(TextView)findViewById(R.id.text1);
tv.setBackgroundDrawable(roundedRectangle);
}
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#f0600000"/>
<stroke android:width="3dp" android:color="#ffff8080"/>
<corners android:radius="5dp"/>
<padding android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp"/>
</shape>
在Java中使用图像
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
GradientDrawable roundedRectangle=(GradientDrawable) this.getResources().getDrawable(R.drawable.my_rounded_rectangle);
TextView tv=(TextView)findViewById(R.id.text1);
tv.setBackgroundDrawable(roundedRectangle);
}
相关文章推荐
- android dialog 去标题,圆角矩形,去背景
- Android安卓自定义圆角矩形控件,省去定义drawable里面xml的麻烦,轻松编程
- android 使用shape定义圆角矩形
- 利用“Nifty Corners Cube”不用css样式表和背景图片实现圆角矩形,超简洁
- Android开发之圆角矩形创建工具RoundRect类定义与用法分析
- android实现圆角矩形背景的方法
- View的圆背景以及圆角矩形背景
- MFC定义圆角矩形按钮
- 不用css样式表和背景图片实现圆角矩形,超简洁!
- 不用css样式表和背景图片实现圆角矩形
- 345_圆角矩形背景
- 工具类:通过shape来设置圆角矩形背景
- android圆角矩形背景
- 不用css样式表和背景图片实现圆角矩形,超简洁!
- android圆角矩形有背景颜色
- android editText 自定义为圆角矩形背景
- Android下基于XML的Graphics shape的高级UI设计,定义圆角背景等
- Android学习笔记(一)——定义色图资源的圆角矩形
- 如何通过代码创建圆角矩形和图片背景选择器
- 用css样式定义圆角背景图片按钮根据文字自适应宽度的方法