当前位置:网站首页>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);
}
}
边栏推荐
- 深入浅出PyTorch中的nn.CrossEntropyLoss
- OpenGL - Lighting
- 一题多解,ASP.NET Core应用启动初始化的N种方案[上篇]
- 22-07-04 西安 尚好房-项目经验总结(01)
- 2311. Longest binary subsequence less than or equal to K
- 干货整理!ERP在制造业的发展趋势如何,看这一篇就够了
- Svgo v3.9.0+
- 22-07-04 Xi'an Shanghao housing project experience summary (01)
- Applet global style configuration window
- 【对象数组的排序】
猜你喜欢
LeetCode 496. Next larger element I
Android privacy sandbox developer preview 3: privacy, security and personalized experience
Hi Fun Summer, play SQL planner with starrocks!
Node collaboration and publishing
Project practice | excel export function
Vs code problem: the length of long lines can be configured through "editor.maxtokenizationlinelength"
[team PK competition] the task of this week has been opened | question answering challenge to consolidate the knowledge of commodity details
Applet (global data sharing)
【组队 PK 赛】本周任务已开启 | 答题挑战,夯实商品详情知识
Can't find the activitymainbinding class? The pit I stepped on when I just learned databinding
随机推荐
LeetCode 496. 下一个更大元素 I
【对象数组a与对象数组b取出id不同元素赋值给新的数组】
Android privacy sandbox developer preview 3: privacy, security and personalized experience
[object array A and object array B take out different elements of ID and assign them to the new array]
SQL learning group by multi table grouping scenario
Creation and reference of applet
Kotlin introductory notes (VIII) collection and traversal
Vs code problem: the length of long lines can be configured through "editor.maxtokenizationlinelength"
LeetCode 556. 下一个更大元素 III
SQL learning alter add new field
Unity SKFramework框架(二十四)、Avatar Controller 第三人称控制
干货整理!ERP在制造业的发展趋势如何,看这一篇就够了
22-07-04 西安 尚好房-项目经验总结(01)
SQL learning - case when then else
浅谈Label Smoothing技术
OpenGL - Coordinate Systems
np. allclose
信息与熵,你想知道的都在这里了
Shutter uses overlay to realize global pop-up
C # image difference comparison: image subtraction (pointer method, high speed)