EditText,TextView,Button,ImageVIew样式
2015-09-29 16:52
465 查看
1:android默认的EditText,TextView,Button都是尖角的,这样看起来效果很丑,我们可以给他设置一个背景从而改变他的样式
例如以下
<EditText
android:id="@+id/et_user"
android:layout_width="275dp"
android:layout_height="40dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="200dp"
android:background="@drawable/bg_yuan_edit"
android:drawableLeft="@drawable/user"
android:hint="请输入用户名"
android:textColor="#818182"/>
其中drawableLeft这个属性可以设置编辑框左边的图片
在这个bg_yuan_edit.xml文件中我们这样编辑:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke android:width="0.5dp" android:color="#33ffffff"/>
<solid android:color="#ffffff"/>
<corners
android:topRightRadius="8dp"
android:bottomLeftRadius="8dp"
android:topLeftRadius="8dp"
android:bottomRightRadius="8dp"
/>
<padding
android:left="10dp"/>
</shape>
这分别设置上下左右的几个尖角的弧形半径。
2:android中使用自定义ImageView使得变为圆角
public class RadioImageView extends ImageView {
public RadioImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
public RadioImageView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public RadioImageView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
Path clipPath = new Path();
int w = this.getWidth();
int h = this.getHeight();
/**
* RectF 圆角矩形
* **/
clipPath.addRoundRect(new RectF(0, 0, w, h), 8.0f, 8.0f,
Path.Direction.CW);
canvas.clipPath(clipPath);
super.onDraw(canvas);
}
}
导入自定义view即可
例如以下
<EditText
android:id="@+id/et_user"
android:layout_width="275dp"
android:layout_height="40dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="200dp"
android:background="@drawable/bg_yuan_edit"
android:drawableLeft="@drawable/user"
android:hint="请输入用户名"
android:textColor="#818182"/>
其中drawableLeft这个属性可以设置编辑框左边的图片
在这个bg_yuan_edit.xml文件中我们这样编辑:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke android:width="0.5dp" android:color="#33ffffff"/>
<solid android:color="#ffffff"/>
<corners
android:topRightRadius="8dp"
android:bottomLeftRadius="8dp"
android:topLeftRadius="8dp"
android:bottomRightRadius="8dp"
/>
<padding
android:left="10dp"/>
</shape>
这分别设置上下左右的几个尖角的弧形半径。
2:android中使用自定义ImageView使得变为圆角
public class RadioImageView extends ImageView {
public RadioImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
public RadioImageView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public RadioImageView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
Path clipPath = new Path();
int w = this.getWidth();
int h = this.getHeight();
/**
* RectF 圆角矩形
* **/
clipPath.addRoundRect(new RectF(0, 0, w, h), 8.0f, 8.0f,
Path.Direction.CW);
canvas.clipPath(clipPath);
super.onDraw(canvas);
}
}
导入自定义view即可
相关文章推荐
- CSS3盒模型display:box详解
- CSS实现垂直居中的5种方法
- ie6,ie7,ie8 css bug兼容解决记录
- 用js+css3做一个小球投篮的动画(easing)
- 基于CSS3的自适应布局技术
- 纯CSS3实现瀑布布局
- 文档流 css中间float clear和布局
- CSS 选择器参考手册
- css 引入新字体
- css outline
- 使用 CSS3 新属性 user-select 控制网页内容的选择范围
- 前端精选文摘:css之GFC 神奇背后的原理(整理)
- 自己写 伪单例 模仿的样式
- css基础
- CSS性能优化探讨
- 纯洁CSS3实现图片墙
- (转载) css实现小三角(尖角)
- 目前流行的CSS+DIV的命名规则
- 使用CSS3的::selection改变选中文本颜色的方法
- IE浏览器下常见的CSS兼容问题