android - 安卓三色渐变
问题描述
我想将我的 android 应用程序的背景设置为三色渐变。我尝试了以下代码行:
binding.splashScreenRelativeLayout.background = gradient
其中 binding 是我的 XML 布局的数据绑定变量,而渐变是
gradient = GradientDrawable(GradientDrawable.Orientation.BL_TR, intArrayOf(startColor, midColor, endColor))
.
我还尝试创建一个自定义可绘制类并将其用作 XML 元素,但没有任何成功,因为我没有找到太多使用 XML 和自定义可绘制对象的文档
解决方案
您是否尝试过创建可绘制资源文件?您可以创建一个形状,并在其中设置一个带有开始、中心和结束颜色的渐变,如下所示:
<shape
xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="@color/colorPrimary"
android:centerColor="@color/colorAccent"
android:endColor="@color/colorPrimaryDark"/>
</shape>
然后你会有一个三色渐变。现在您要做的就是将其设置为布局文件的背景。
推荐阅读
- javascript - 对数组应用条件
- azure - 如何知道 azure 角色分配已经存在
- javascript - 地图功能不起作用我做错了什么?
- ignite - 获取 Ignite 客户端-服务器连接信息
- unit-testing - 如何在构建管道的单元测试失败时从 Azure DevOps 向特定开发人员发送详细的电子邮件?
- terraform - Terraform vm_name_prefix 自动增量修改
- sql - Oracle sql查询返回第一次来的客户
- javascript - 登录后Firebase慢速重定向?
- angular - 未随 HTTP 请求发送的标头
- android - xamarin.uitest 的最低支持平台版本