android渐变色,边角,边框,

这篇博客介绍了如何在Android中实现颜色的透明度调节,去除EditText底部横线,以及如何创建XML drawable来设置渐变色、边角、边框。通过在res/drawable目录下创建XML文件,使用`android:background="@drawable/xxxx.xml"`引用,可以实现如渐变色、白色边框的半透明效果和单边圆角等效果。同时提到了`<shape>`元素的不同类型,如oval、ring、rectangle和line,并强调了opacity属性对透明度的控制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.颜色, 是可以设置透明属性的,正常是都是100%不透明。

<color name="white">#ffffff</color>

调整透明度后

<color name="hintWhite">#77ffffff</color>

如何设置:在AS中点击颜色,最下方的Opacity,是透明度,0-255

2.设置EditText取消底部横线

style="?android:attr/textViewStyle"
android:background="@null"

3.总览设置渐变色,边角,实心/空心,边框
创建 在该文件夹下res/drawable/xxxx. xml
调用 android:background=”@drawable/xxxx.xml”

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape=["rectangle" | "oval" | "line" | "ring"] >   --- 默认为rectangle
    <corners  -- shape=“rectangle”时使用, 
        android:radius="integer"  -- 半径,会被下边的属性覆盖,默认为1dp,
        android:topLeftRadius="integer" 
        android:topRightRadius="integer"
        android:bottomLeftRadius="integer"
        android:bottomRightRadius="integer" />
    <gradient  -- 渐变
        android:angle="integer"
        android:centerX="integer"
        android:centerY="integer"
        android:centerColor="integer"
        android:endColor="color"
        android:gradientRadius="integer"
        android:startColor="color"
        android:type=["linear" | "radial" | "sweep"]
        android:useLevel=["true" | "false"] />
    <padding
        android:left="integer"
        android:top="integer"
        android:right="integer"
        android:bottom="integer" />
    <size    -- 指定大小,一般用在imageview配合scaleType属性使用。大小一般会适配滴
        android:width="integer"
        android:height="integer" />
    <solid    -- 填充颜色,可是是十六进制颜色。(比如想设置半透明效果,直接使用十六就只就OK)
        android:color="color" />
    <stroke    -- 指定边框,border,dashWidth和dashGap有一个为0dp则为实线
        android:width="integer"
        android:color="color"
        android:dashWidth="integer"    -- 虚线宽度
        android:dashGap="integer" />    -- 虚线间隔宽度
</shape>

渐变色

<!--android:startColor="#aa000000"  渐变起始色值  
   android:centerColor=""      渐变中间色值  
   android:endColor="#ffffffff"    渐变结束颜色  
   android:angle="45"     渐变的方向 默认为0 从做向右 ,90时从下向上 必须为45的整数倍  
   android:type="radial"  渐变类型 有三种 线性linear 放射渐变radial 扫描线性渐变sweep      
   android:centerX="0.5"   渐变中心相对X坐标只有渐变类型为放射渐变时有效  
   android:centerY="0.5"   渐变中心相对Y坐标只有渐变类型为放射渐变时有效  
   android:gradientRadius="100"    渐变半径 非线性放射有效  
   -->  
<gradient  
    android:startColor="#000000"  
    android:endColor="#ffffff"  
   android:type="sweep"  
    android:centerX="0.5"  
   android:centerY="0.5"  
   android:gradientRadius="100"/>

白色边框,半透明效果

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
    <corners android:radius="16dp" />
    <!-- 这是半透明,还可以设置全透明,那就是白色边框的效果了 -->
    <solid android:color="#80065e8d" />
    <stroke
        android:dashGap="0dp"
        android:width="4dp"
        android:color="@android:color/white" />
</shape>

单边曲角效果

<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">
    <corners 
        android:topLeftRadius="5dp"
        android:topRightRadius="5dp"
        android:bottomLeftRadius="30dp"
        android:bottomRightRadius="30dp"/>
</shape>

oval 椭圆 ring 环形物 rectangle 矩形 line 线 opacity 不透明性

附上一份颜色进制图,需要的可以查阅: http://blog.sina.com.cn/s/blog_684a1d160100umuq.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值