材质设计中Android棒棒糖上的半透明渐变状态栏
我想做这样的东西 适用于Android 5.0及以上版本 我如何实现这一点?我在StackOverFlow或android开发者网站上找不到任何解决方案 我建议我可以使状态栏透明,并在状态栏下绘制渐变。但问题不多 第一个问题是,形状可拉伸的常用渐变不支持材料设计规范材质设计中Android棒棒糖上的半透明渐变状态栏,android,material-design,android-appbarlayout,Android,Material Design,Android Appbarlayout,我想做这样的东西 适用于Android 5.0及以上版本 我如何实现这一点?我在StackOverFlow或android开发者网站上找不到任何解决方案 我建议我可以使状态栏透明,并在状态栏下绘制渐变。但问题不多 第一个问题是,形状可拉伸的常用渐变不支持材料设计规范 第二个问题是,我无法通过android:fitsSystemWindows=“true”将map fragment适配到windows,给出与材料设计网站上显示的大致相同绘图的公式是: y = 3/(4*(x+0.5)) - 0.
第二个问题是,我无法通过android:fitsSystemWindows=“true”将map fragment适配到windows,给出与材料设计网站上显示的大致相同绘图的公式是:
y = 3/(4*(x+0.5)) - 0.5
我尝试了几种通过画布绘制双曲面梯度的方法,找到了最快的解决方案
public class HyperbolaGradientDrawable extends Drawable {
private static final int ALPHA_DEFAULT = (int) (0.6f * 255);
private int mAlpha = ALPHA_DEFAULT;
private int mColor;
private Rect mBmpRect = new Rect();
private int[] mColors = new int[0];
private Bitmap mBmp;
@Override
public void draw(Canvas canvas) {
Rect bounds = getBounds();
if (mColors.length != bounds.height()) {
int alpha;
float y, alphaRelative;
mColors = new int[bounds.height()];
for (int i = 0; i < bounds.height(); i++) {
y = ((float) i) / bounds.height();
// this function gives approximately 0.5 of the bearing alpha at 3/10ths closed to the darker end
alphaRelative = 3 / (4 * (y + 0.5f)) - 0.5f;
alpha = (int) (alphaRelative * mAlpha);
mColors[i] = alpha << 24 | mColor;
}
mBmp = Bitmap.createBitmap(mColors, 1, bounds.height(), Bitmap.Config.ARGB_8888);
mBmpRect.set(0, 0, 1, bounds.height());
}
canvas.drawBitmap(mBmp, mBmpRect, bounds, null);
}
public void setColor(int color) {
// remove alpha chanel
mColor = color & 0x00FFFFFF;
}
@Override
public void setAlpha(int alpha) {
mAlpha = alpha;
}
@Override
public void setColorFilter(ColorFilter colorFilter) {
}
@Override
public int getOpacity() {
return PixelFormat.TRANSLUCENT;
}
}
公共类双曲梯度可绘制扩展可绘制{
私有静态最终int ALPHA_默认值=(int)(0.6f*255);
private int mAlpha=ALPHA_默认值;
私人内特彩色;
private Rect mBmpRect=new Rect();
private int[]mColors=new int[0];
私有位图mBmp;
@凌驾
公共空白绘制(画布){
Rect bounds=getBounds();
if(mColors.length!=bounds.height()){
int-alpha;
浮动y,字母相对;
mColors=newint[bounds.height()];
对于(int i=0;i mColors[i]=alpha如果您否定我的问题,请描述StackOverFlow中发布的任何解决方案,或者在评论中描述我的问题中的问题。如果您使用9-Patch,绘制渐变不是问题。您可以向我们展示您已经尝试过的(代码),你得到了什么,你期望得到什么?有什么解决方案吗?在同一个问题上结结巴巴,但没有找到任何方法。你只是想让渐变位于工具栏/操作栏的顶部,还是应该向下延伸更远?