android输入框边框椭圆

在Android程序开发中,我们经常会去用到Shape这个东西去定义各种各样的形状,shape可以绘制矩形环形以及椭圆,所以只需要用椭圆即可,在使用的时候将控件比如imageview或textview的高宽设置成一样就是正圆,solid表示远的填充色,stroke则代表远的边框线,所以两者结合可以实现带边缘的圆,当然也可以直接加上size控制高宽。那么我首先带你们了解一下Shape下有哪些标签,并且都代表什么意思:

shape属性:

rectangle:矩形

oval:椭圆

line:线,需要 stroke 来设置宽度

ring:环形

solid属性:

color:填充颜色

stroke属性:

color:边框颜色

width:边框宽度

dashWidth:虚线框的宽度

dashGap:虚线框的间隔

corners属性:

radius:四个角的半径

topRightRadius:右上角的半径

bottomLeftRadius:右下角的半径

opLeftRadius:左上角的半径

bottomRightRadius:左下角的半径

gradient属性:

startColor:其实颜色

centerColor:中间颜色

endColor:结束颜色

centerX:中间颜色的相对X坐标(0 -- 1)

centerY:中间颜色的相对Y坐标(0 -- 1)

useLevel:(true/false), 是否用作LevelListDrawable的标志

angle是渐变角度,必须为45的整数倍。0从左到右,90从下到上,180从右到左,270从上到下

type:渐变模式。 默认线性渐变,可以指定渐变为radial(径向渐变)或者sweep(类似雷达扫描的形式)

gradientRadius:渐变半径,径向渐变需指定半径。

padding属性:

left:左内边距

top:上内边距

right:右内边距

bottom:下内边距

size属性:

width:宽

height:高

<?xml version="1.0" encoding="utf-8" ?>
<!--相当于做了一张圆角的图片,然后给button作为背景图片-->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <!--设置背景色-->
   
    <!--设置圆角-->
    <corners android:radius="105dip" />
    <padding
    android:bottom="5dp"
    android:left="10dp"
    android:right="10dp"
    android:top="5dp"
    />
    <!--设置边框线的宽度和颜色-->
    <stroke android:width="5px" android:color="#000000" />
    <selector
  xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@color/blue"></item>
   <item android:state_pressed="false" android:drawable="@color/yellow"></item>
</selector>

</shape>

 

posted @ 2022-01-03 17:03  zrswheart  阅读(711)  评论(0编辑  收藏  举报