Search code examples
androidblurblurry

Android Libs Blurry Not Working


I use https://github.com/wasabeef/Blurry library.

in Onclick, the following code works.

private boolean blurred = false;

if (blurred) {
      Blurry.delete((ViewGroup) findViewById(R.id.content));
    } else {
      long startMs = System.currentTimeMillis();
      Blurry.with(MainActivity.this)
          .radius(25)
          .sampling(2)
          .async()
          .animate(500)
          .onto((ViewGroup) findViewById(R.id.content));
    }
blurred = !blurred;

But when I add the following code in OnCreate, it doesn't work.

Blurry.with(MainActivity.this)
      .radius(25)
      .sampling(2)
      .async()
      .animate(500)
      .onto((ViewGroup) findViewById(R.id.content));

Solution

  • Your library uses view size

      factor.width = target.getMeasuredWidth();
      factor.height = target.getMeasuredHeight();
    

    When you call it. In onCreate your view has not created. you should move it for example to onWindowFocusChanged(boolean hasFocus) or use any suggestion from answer of for3st by this link