当前位置:网站首页>Gradientdrawable get a single color
Gradientdrawable get a single color
2022-07-05 09:33:00 【Xu Jiajia 233】
summary
GradientDrawable Although it's powerful , In normal use , There are many scenes that only use shape related functions , For example, it is used to draw a circle or a rounded rectangle , The general code is as follows :
View vTest = findViewById(R.id.v_main_test);
GradientDrawable gradientDrawable = new GradientDrawable();
gradientDrawable.setColor(0xFFFF0000);
gradientDrawable.setCornerRadius(20);
vTest.setBackground(gradientDrawable);
Get a single color
If only GradientDrawable A single color is set in ,GradientDrawable There is no specially obtained interface in , The relevant logic needs to be implemented according to the corresponding interface , as follows :
if (vTest.getBackground() instanceof GradientDrawable) {
GradientDrawable gradientDrawable = (GradientDrawable) vTest.getBackground();
ColorStateList colorStateList = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
colorStateList = gradientDrawable.getColor();
int singleColor = colorStateList.getColorForState(gradientDrawable.getState(), Color.WHITE);
Log.i("test_log", "singleColor:" + singleColor);
}
}
边栏推荐
- A detailed explanation of the general process and the latest research trends of map comparative learning (gnn+cl)
- Unity SKFramework框架(二十三)、MiniMap 小地图工具
- Applet (use of NPM package)
- [object array A and object array B take out different elements of ID and assign them to the new array]
- 浅谈Label Smoothing技术
- Multiple solutions to one problem, asp Net core application startup initialization n schemes [Part 1]
- Nodemon installation and use
- OpenGL - Coordinate Systems
- Generate confrontation network
- [how to disable El table]
猜你喜欢
Go 语言使用 MySQL 的常见故障分析和应对方法
An article takes you into the world of cookies, sessions, and tokens
使用el-upload封装得组件怎么清空已上传附件
Kotlin introductory notes (II) a brief introduction to kotlin functions
nodejs_ fs. writeFile
LeetCode 496. 下一个更大元素 I
顶会论文看图对比学习(GNN+CL)研究趋势
[team PK competition] the task of this week has been opened | question answering challenge to consolidate the knowledge of commodity details
SQL learning - case when then else
【sourceTree配置SSH及使用】
随机推荐
L'information et l'entropie, tout ce que vous voulez savoir est ici.
SQL learning group by multi table grouping scenario
Introduction Guide to stereo vision (7): stereo matching
Jenkins pipeline method (function) definition and call
uni-app---uni.navigateTo跳转传参使用
Node の MongoDB Driver
My life
c语言指针深入理解
Principle and performance analysis of lepton lossless compression
High performance spark_ Transformation performance
Applet network data request
C # image difference comparison: image subtraction (pointer method, high speed)
C语言-从键盘输入数组二维数组a,将a中3×5矩阵中第3列的元素左移到第0列,第3列以后的每列元素行依次左移,原来左边的各列依次绕到右边
一篇文章带你走进cookie,session,Token的世界
初识结构体
Unity skframework framework (XXIII), minimap small map tool
Lepton 无损压缩原理及性能分析
[ctfhub] Title cookie:hello guest only admin can get flag. (cookie spoofing, authentication, forgery)
Thermometer based on STM32 single chip microcomputer (with face detection)
【对象数组a与对象数组b取出id不同元素赋值给新的数组】