react-native-navigation的迁移库

TranslucentTitleBarBackground.java 1.3KB

12345678910111213141516171819202122232425262728293031323334353637
  1. package com.reactnativenavigation.views;
  2. import android.graphics.Color;
  3. import android.graphics.LinearGradient;
  4. import android.graphics.Shader;
  5. import android.graphics.drawable.PaintDrawable;
  6. import android.graphics.drawable.ShapeDrawable;
  7. import android.graphics.drawable.shapes.RectShape;
  8. class TranslucentTitleBarBackground extends PaintDrawable {
  9. TranslucentTitleBarBackground() {
  10. setShape(new RectShape());
  11. createShader();
  12. }
  13. private void createShader() {
  14. ShapeDrawable.ShaderFactory sf = new ShapeDrawable.ShaderFactory() {
  15. @Override
  16. public Shader resize(int width, int height) {
  17. double angleInRadians = Math.toRadians(90);
  18. int x1 = (int) (Math.cos(angleInRadians) * width);
  19. int y1 = (int) (Math.sin(angleInRadians) * height);
  20. int[] colors = new int[]{Color.argb(90, 0, 0, 0), Color.argb(15, 0, 0, 0), Color.TRANSPARENT};
  21. float[] positions = {0, 0.78f, 1};
  22. LinearGradient lg = new LinearGradient(0, 0, x1, y1,
  23. colors,
  24. positions,
  25. Shader.TileMode.REPEAT);
  26. return lg;
  27. }
  28. };
  29. setShaderFactory(sf);
  30. }
  31. }