Posted at

Androidで部分的なViewをぼかす

More than 1 year has passed since last update.


build.gradle

defaultConfig {

// for blurview
renderscriptTargetApi 25
renderscriptSupportModeEnabled true
}

dependencies {
compile 'com.eightbitlab:blurview:1.3.0'
}


activity_main.xml

<eightbitlab.com.blurview.BlurView

android:id="@+id/blurview"
android:layout_width="match_parent"
app:blurOverlayColor="@android:color/transparent">
</eightbitlab.com.blurview.BlurView>

blurOverlayColor は標準の transparent を指定。


MainActivity.java

final float radius = 16;

final View decorView = getWindow().getDecorView();
final ViewGroup rootView = (ViewGroup) decorView.findViewById(R.id.activity_main);
final Drawable windowBackground = decorView.getBackground();

BlurView blurView = (BlurView) findViewById(R.id.blurview);
blurView.setupWith(rootView)
.windowBackground(windowBackground)
.blurAlgorithm(new RenderScriptBlur(this, true))
.blurRadius(radius);


検討したもの