导航:首页 > 操作系统 > android字体颜色渐变

android字体颜色渐变

发布时间:2025-07-28 17:59:40

android studio中怎么将方形按钮设置成圆角以及渐变效果

一、在 studio中res 包下的drawable中建立一个shape的文件,系统会给你一个默认的方形然后你就可以开始设置你需要的效果。
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:Android="http://schemas.android.com/apk/res/android">

<!--填充背景色 -->
<solid android:color="#ffff00" /> //solid 指的是背景颜色的设置

<!--描边 他需要 2个参数,颜色 第二参数 宽度 -->
<stroke
android:width="2dp" //width 指的是边框的宽度
android:color="#ff00ff" /> //color指的是边框的颜色

<!-- 设置弧度 Radius设置所有角的弧度 --> //radius 指的就是角的弧度
<corners //方形存在四个角,我们可以同时设置四个角,也可以分开设置
android:bottomLeftRadius="20dp" //左下角
android:bottomRightRadius="20dp" //右下角
android:topLeftRadius="20dp" //左上角
android:topRightRadius="20dp" /> //右上角

//同时设置:<corners
android:Radius="20dp" /> //四个角同时设置

<!-- 渐变色 startColor 启示颜色 endColor最终颜色 type类型(如果类型为radial(径向渐变,一个圆心以半径的方式渐变),必须加上 android:gradientRadius="**")-->
<gradient
android:startColor="#ff0000" //开始颜色
android:endColor="#ffffff" //结束颜色
android:type="linear" /> //水平渐变 从左到右 type 指的是渐变的模式

<!--内容与边框的间距-->
<padding
android:bottom="15dp"
android:left="15dp"
android:right="15dp"
android:top="15dp" />

<!--如果设置了渐变色 那么背景颜色将不显示 -->

</shape>
<gradient>
shape的颜色渐变属性
attributes:

android:angle
Integer,代表渐变颜色的角度, 0 is left to right, 90 is bottom to top. 必须是45的整数倍.
默认是 0.该属性只有在type=linear情况下起作用,默认的type为linear。
默认情况下,从左到右:

xml代码:<gradient
android:startColor="#000000"
android:endColor="#ffffff"
/>

angle=270,从上到下 :

xml代码:<gradient
android:startColor="#000000"
android:endColor="#ffffff"
android:angle="270"
/>
android:startColor
Color. 颜色渐变的开始颜色,如angle=270中的 android:startColor="#000000"
android:endColor
Color. 颜色渐变的结束颜色,如angle=270中的 android:endColor="#ffffff"
android:centerColor
Color. 颜色渐变的中间颜色,主要用于多彩。

<gradient
android:startColor="#000000"
android:endColor="#ffffff"
android:centerColor="#ff0000"
/>
android:centerX
Float.(0 - 1.0) 相对X的渐变位置。
android:centerY
Float.(0 - 1.0) 相对Y的渐变位置。
这两个属性只有在type不为linear情况下起作用。
android:gradientRadius
Float. 渐变颜色的半径,单位应该是像素点. 需要 android:type="radial".
如果android:type="radial",没有设置android:gradientRadius,将会报错,error inflating class.

xml代码:
<gradient
android:startColor="#ff0000"
android:endColor="#ffffff"
android:centerX="0.5"
android:centerY="0.5"
android:gradientRadius="30"
android:type="radial"
/>
加入Android:centerColor属性

<gradient
android:startColor="#ff0000"
android:endColor="#ffffff"
android:centerColor="#000000"
android:centerX="0.5"
android:centerY="0.5"
android:gradientRadius="30"
android:type="radial"
/>
android:type
Value Description
"linear" 线性渐变.可以理解为 y=kx+b.
"radial" A radial gradient.圆形渐变,起始颜色从cenralX,centralY点开始。
"sweep" A sweeping line gradient.

centerX="0.2" centerX="0.2"

xml代码:
<gradient
android:startColor="#ff0000"
android:endColor="#ffffff"
android:centerX="0.2"
android:centerX="0.2"
android:gradientRadius="30"
android:type="radial"
/>
type="sweep":

xml代码:
<gradient
android:startColor="#ff0000"
android:endColor="#ffffff"
android:centerX="0.5"
android:centerY="0.5"
android:type="sweep"
/>

Ⅱ android shape怎么用

下图是安卓无忧中的例子,可以看里面的源码还有文档,网络一下安卓无忧,然后下载就行,大部分形状都可以定义,请看截图:

在Android程序开发中,我们经常会去用到Shape这个东西去定义各种各样的形状,首先我们了解一下

Shape下面有哪些标签,都代表什么意思:

1.1 solid:填充

android:color指定填充的颜色

1.2 gradient:渐变

android:startColor和android:endColor分别为起始和结束颜色,

android:angle是渐变角度,必须为45的整数倍。

另外渐变默认的模式为android:type="linear",即线性渐变,

可以指定渐变为径向渐变,android:type="radial",径向渐变需要指定半径android:gradientRadius="50"。

angle值对应的位置如图:

1.3 stroke:描边

android:width="2dp" 描边的宽度,android:color 描边的颜色。

我们还可以把描边弄成虚线的形式,设置方式为:

android:dashWidth="5dp"

android:dashGap="3dp"

其中android:dashWidth表示'-'这样一个横线的宽度,android:dashGap表示之间隔开的距离

1.4 corners:圆角

android:radius为角的弧度,值越大角越圆。

我们还可以把四个角设定成不同的角度,

同时设置五个属性,则Radius属性无效

android:Radius="20dp" 设置四个角的半径

android:topLeftRadius="20dp" 设置左上角的半径

android:topRightRadius="20dp" 设置右上角的半径

android:bottomLeftRadius="20dp" 设置右下角的半径

android:bottomRightRadius="20dp" 设置左下角的半径

padding:间隔

可以设置上下左右四个方向的间隔

ps:为了方便交流请关注一下我的微博哦哦。

Ⅲ android颜色渐变如何实现从四周往中心渐变 或者从中心往四周渐变 都行,不是 从左往右

android 颜色渐变是指通知xml或者java代码,设置相关参数,是界面的某个指定的视图显示成从开始位置的颜色,逐渐过度到结尾位置的颜色的技术。

android颜色渐变的分类有:

LinearGradient线性渐变

RadialGradient镜像渐变

SweepGradient角度渐变


一、LinearGradient线性渐变
顾名思义,是只颜色在一个直线方向上逐渐改变。

文件代码:

<?xmlversion="1.0"encoding="utf-8"?>
<shapexmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">

<gradient
android:endColor="#0000FF"
android:startColor="#FF0000"
android:type="linear"/>

</shape>

效果:

Ⅳ 如何通过android实现alpha渐变动画效果

Android动画分为四种:alpha(渐变透明度),scale(渐变尺寸伸缩),translate(画面转换位置移动),rotate(画面转移旋转);今天先写第一个动画alpha。
动画效果有两种实现:
一、在xml中定义:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 透明度控制动画效果 alpha
浮点型值:
fromAlpha 属性为动画起始时透明度
toAlpha 属性为动画结束时透明度
说明:
0.0表示完全透明
1.0表示完全不透明
以上值取0.0-1.0之间的float数据类型的数字

长整型值:
ration 属性为动画持续时间
说明:
时间以毫秒为单位
-->

<alpha
android:fromAlpha="0.1"
android:toAlpha="1.0"
android:ration="5000"
/>

</set>
二、在页面Activity中声明:
Animation animation = new AlphaAnimation(0.1f, 1.0f);
animation.setDuration(5000);

完成动画渐变透明度的参数设定后,我们就要开始在应用中使用它:
public class SplashActivity extends Activity{

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome);

View view = View.inflate(SplashActivity.this, R.layout.welcome, null);
setContentView(view);
//动画效果参数直接定义
Animation animation = new AlphaAnimation(0.1f, 1.0f);
animation.setDuration(5000);

//动画效果从XMl文件中定义
// Animation animation = AnimationUtils.loadAnimation(this, R.anim.alpha);
view.setAnimation(animation);
}
}
这样我们就完成了预定的动画效果,但是我们的最终目的是动画效果完毕以后跳转到相应的页面,所以我们对动画添加了监听:
animation.setAnimationListener(new AnimationListener() {

@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub

}

@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub

}

@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
Intent intent = new Intent(SplashActivity.this,MainActivity.class);
startActivity(intent);
}
});
这样的话,我们在动画的持续时间中预加载我们的资源,当动画结束以后跳转到我们的主页面;
详细步骤和完整源码可以参考:http://www.cnblogs.com/sishuiliuyun/p/3167581.html

阅读全文

与android字体颜色渐变相关的资料

热点内容
求是在哪个APP可以看 浏览:295
照片加密不能拷贝 浏览:346
APP的许可文件放哪里 浏览:855
三菱plcfb程序未编译 浏览:568
程序员最怕什么物品 浏览:696
安卓最好的模拟器是什么 浏览:248
一建教材pdf免费下载 浏览:90
怎么快速建立多个文件夹视频 浏览:435
算计pdf 浏览:999
ae无法连接到服务器什么意思 浏览:806
程序员面试谈谈个人最大特色 浏览:97
团购服务器怎么样 浏览:913
android的四大基本组件 浏览:838
mac压缩文件命令 浏览:543
php面向对象高级 浏览:390
linux下查看服务 浏览:778
键盘怎么连接单片机 浏览:758
大数据服务器云主机 浏览:724
java字符串的复制 浏览:369
android封装sdk 浏览:428