当前位置:网站首页>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);
}
}
边栏推荐
- An article takes you into the world of cookies, sessions, and tokens
- 植物大战僵尸Scratch
- OpenGL - Lighting
- 基于STM32单片机的测温仪(带人脸检测)
- Creation and reference of applet
- 微信小程序获取住户地区信息
- Svg optimization by svgo
- Can't find the activitymainbinding class? The pit I stepped on when I just learned databinding
- OpenGL - Model Loading
- MySQL does not take effect in sorting string types
猜你喜欢
22-07-04 Xi'an Shanghao housing project experience summary (01)
Can't find the activitymainbinding class? The pit I stepped on when I just learned databinding
OpenGL - Model Loading
Applet data attribute method
【组队 PK 赛】本周任务已开启 | 答题挑战,夯实商品详情知识
Using request headers to develop multi terminal applications
LeetCode 556. 下一个更大元素 III
OpenGL - Coordinate Systems
Figure neural network + comparative learning, where to go next?
Nodemon installation and use
随机推荐
微信小程序获取住户地区信息
Kotlin introductory notes (VI) interface and function visibility modifiers
My life
Thermometer based on STM32 single chip microcomputer (with face detection)
干货整理!ERP在制造业的发展趋势如何,看这一篇就够了
[team PK competition] the task of this week has been opened | question answering challenge to consolidate the knowledge of commodity details
Rebuild my 3D world [open source] [serialization-2]
【ManageEngine】如何利用好OpManager的报表功能
利用请求头开发多端应用
[two objects merged into one object]
云计算技术热点
使用el-upload封装得组件怎么清空已上传附件
测试老鸟浅谈unittest和pytest的区别
C form click event did not respond
c语言指针深入理解
Alibaba's ten-year test brings you into the world of APP testing
LeetCode 31. 下一个排列
2309. 兼具大小写的最好英文字母
STM32简易多级菜单(数组查表法)
Progressive JPEG pictures and related