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);
検討したもの
- android - dim/blur a parent layout background - Stack Overflow
- GitHub - Dimezis/BlurView: Dynamic iOS-like blur of underlying Views for Android
- GitHub - wl9739/BlurredView: Dynamic blur of image views for Android
- GitHub - wonderkiln/blurkit-android: The missing Android blurring library. Fast blur-behind layout that parallels iOS.