当前位置:网站首页>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);
}
}
边栏推荐
- Android privacy sandbox developer preview 3: privacy, security and personalized experience
- Transfer learning and domain adaptation
- LeetCode 31. 下一个排列
- It's too difficult to use. Long articles plus pictures and texts will only be written in short articles in the future
- 图神经网络+对比学习,下一步去哪?
- Wxss template syntax
- 信息与熵,你想知道的都在这里了
- 【el-table如何禁用】
- 信息與熵,你想知道的都在這裏了
- C # compare the differences between the two images
猜你喜欢
随机推荐
基于STM32单片机的测温仪(带人脸检测)
Editor use of VI and VIM
基于宽表的数据建模应用
Lepton 无损压缩原理及性能分析
OpenGL - Lighting
利用请求头开发多端应用
【两个对象合并成一个对象】
【PyTorch Bug】RuntimeError: Boolean value of Tensor with more than one value is ambiguous
深入浅出PyTorch中的nn.CrossEntropyLoss
云计算技术热点
浅谈Label Smoothing技术
What is a firewall? Explanation of basic knowledge of firewall
C语言-从键盘输入数组二维数组a,将a中3×5矩阵中第3列的元素左移到第0列,第3列以后的每列元素行依次左移,原来左边的各列依次绕到右边
OpenGL - Model Loading
信息與熵,你想知道的都在這裏了
2311. 小于等于 K 的最长二进制子序列
【el-table如何禁用】
[ManageEngine] how to make good use of the report function of OpManager
2310. 个位数字为 K 的整数之和
阿里云发送短信验证码








