欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  互联网

GradientDrawable

程序员文章站 2022-06-23 14:17:36
一、GradientDrawable是什么?GradientDrawable是shape标签的代码实现。对于项目中非通用的样式,可以通过代码创建或修改公共样式,无需针对每个样式创建一个.xml文件实现。二、GradientDrawable怎么使用?1、新创建GradientDrawable background = new GradientDrawable();background.setColor(Color.RED);view.setBackgroundDrawable(bac...

一、GradientDrawable是什么?

GradientDrawable是shape标签的代码实现。对于项目中非通用的样式,可以通过代码创建或修改公共样式,无需针对每个样式创建一个.xml文件实现。

二、GradientDrawable怎么使用?

1、新创建
GradientDrawable background = new GradientDrawable();
background.setColor(Color.RED);
view.setBackgroundDrawable(background);

2、对shape标签修改

//bg_accent.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle">
    <solid android:color="@color/colorAccent"/>
</shape>
GradientDrawable drawable = (GradientDrawable) mContext.getResources().getDrawable(R.drawable.bg_accent);
drawable.setColor(Color.RED);
view.setBackgroundDrawable(drawable)

 

本文地址:https://blog.csdn.net/yufumatou/article/details/108847438

相关标签: Android