您的位置:首页 > Web前端 > CSS

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即可
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: