在布局中有时会用到背景渐变色,呈现一定的效果。只需要设定startColor和endColor,系统会自动生成渐变的背景。
1. 在res/drawable下面创建.xml文件,内容为:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#0525f5"
android:endColor="#c70cdf"
android:angle="270"
/>
<!--angle 必须为45的倍数,angle 不同渐变角度不同,具体效果自行尝试
-->
</shape>
- 在res/layout中直接使用:
可以作为背景或者图片的src:
android:src="@drawable/background_regist"
android:background="@drawable/background_regist"
本文介绍如何在Android应用中设置背景渐变色。通过创建一个XML文件并定义startColor和endColor属性,即可轻松实现从一种颜色过渡到另一种颜色的效果。文章提供了具体的代码示例。
584

被折叠的 条评论
为什么被折叠?



