当前位置:网站首页>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);
}
}
边栏推荐
- OpenGL - Model Loading
- Newton iterative method (solving nonlinear equations)
- 2310. The number of bits is the sum of integers of K
- 云计算技术热点
- Unity skframework framework (XXII), runtime console runtime debugging tool
- Transfer learning and domain adaptation
- C语言-从键盘输入数组二维数组a,将a中3×5矩阵中第3列的元素左移到第0列,第3列以后的每列元素行依次左移,原来左边的各列依次绕到右边
- A keepalived high availability accident made me learn it again
- C # image difference comparison: image subtraction (pointer method, high speed)
- Nodejs modularization
猜你喜欢
VS Code问题:长行的长度可通过 “editor.maxTokenizationLineLength“ 进行配置
【ManageEngine】如何利用好OpManager的报表功能
Introduction Guide to stereo vision (4): DLT direct linear transformation of camera calibration [recommended collection]
Shutter uses overlay to realize global pop-up
Priority queue (heap)
【sourceTree配置SSH及使用】
High performance spark_ Transformation performance
Information and entropy, all you want to know is here
Applet network data request
nodejs_ fs. writeFile
随机推荐
Newton iterative method (solving nonlinear equations)
c语言指针深入理解
2309. 兼具大小写的最好英文字母
Multiple solutions to one problem, asp Net core application startup initialization n schemes [Part 1]
Unity skframework framework (XXII), runtime console runtime debugging tool
Jenkins pipeline method (function) definition and call
阿里云发送短信验证码
Transfer learning and domain adaptation
Svg optimization by svgo
【数组的中的某个属性的监听】
LeetCode 31. 下一个排列
我的一生.
使用el-upload封装得组件怎么清空已上传附件
【对象数组的排序】
LeetCode 503. 下一个更大元素 II
Kotlin introductory notes (VII) data class and singleton class
[two objects merged into one object]
The research trend of map based comparative learning (gnn+cl) in the top paper
C # image difference comparison: image subtraction (pointer method, high speed)
Composition of applet code