我想创建一个透明覆盖层以在标题栏上创建投影。
我在构造函数中创建自定义 View
GradientDrawable drawable = new GradientDrawable(Orientation.BOTTOM_TOP, new int[]{
Color.TRANSPARENT,
Color.BLACK,
Color.BLACK });
drawable.setGradientType(GradientDrawable.LINEAR_GRADIENT);
// drawable.setAlpha(255);
this.setBackgroundDrawable(drawable);
View 不会出现在屏幕上。如果我删除 Color.TRANSPARENT, View 会出现,但我需要渐变必须有 50% 的 alpha。
有什么想法吗?
谢谢。
最佳答案
试试这个颜色
int colors[] = { 0x00000000 , 0x40000000, 0x80000000 };
只用一个8位的颜色值ARGB
关于Android创建带渐变的透明层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15984874/