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即可
实现圆形的View
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
android:useLevel="false">
<!-- 实心 -->
<solid android:color="@color/label_round_orange" />
<!-- 圆角 -->
<corners android:radius="360dp" />
<!-- 边距 -->
<padding
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp" />
<!-- 大小 -->
<size android:width="15dp"
android:height="15dp" />
</shape>
textview中显示如下