EditText,TextView,Button,ImageVIew样式

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中显示如下



   

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

优雅的心情

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值