当前位置:网站首页>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);
}
}
边栏推荐
- 微信小程序获取住户地区信息
- 阿里云发送短信验证码
- Cloud computing technology hotspot
- Deep understanding of C language pointer
- [ctfhub] Title cookie:hello guest only admin can get flag. (cookie spoofing, authentication, forgery)
- Unity SKFramework框架(二十四)、Avatar Controller 第三人称控制
- Applet (global data sharing)
- High performance spark_ Transformation performance
- Information and entropy, all you want to know is here
- . Net service governance flow limiting middleware -fireflysoft RateLimit
猜你喜欢

Unity skframework framework (24), avatar controller third person control

LeetCode 503. Next bigger Element II

Introduction Guide to stereo vision (6): level constraints and polar correction of fusiello method
![[ctfhub] Title cookie:hello guest only admin can get flag. (cookie spoofing, authentication, forgery)](/img/78/d9d1a66fc239e7c62de1fce426d30d.jpg)
[ctfhub] Title cookie:hello guest only admin can get flag. (cookie spoofing, authentication, forgery)

一次 Keepalived 高可用的事故,让我重学了一遍它

C form click event did not respond

Wxml template syntax

Hosting environment API

Go 语言使用 MySQL 的常见故障分析和应对方法

Principle and performance analysis of lepton lossless compression
随机推荐
Kotlin introductory notes (VIII) collection and traversal
Transfer learning and domain adaptation
LeetCode 503. 下一个更大元素 II
Svgo v3.9.0+
A keepalived high availability accident made me learn it again
Figure neural network + comparative learning, where to go next?
Kotlin introductory notes (II) a brief introduction to kotlin functions
Introduction Guide to stereo vision (4): DLT direct linear transformation of camera calibration [recommended collection]
SQL learning group by multi table grouping scenario
Multiple solutions to one problem, asp Net core application startup initialization n schemes [Part 1]
使用el-upload封装得组件怎么清空已上传附件
【饿了么动态表格】
[ctfhub] Title cookie:hello guest only admin can get flag. (cookie spoofing, authentication, forgery)
nodejs_ 01_ fs. readFile
Kotlin introductory notes (VI) interface and function visibility modifiers
Nodemon installation and use
Principle and performance analysis of lepton lossless compression
2311. Longest binary subsequence less than or equal to K
【对象数组a与对象数组b取出id不同元素赋值给新的数组】
Talking about label smoothing technology