我尝试使用Dimezis的BlurView library在Android上创建模糊效果,但它根本没用。
我遵循了所有指示,但它仍然没有任何效果。
以下是我将BlurView布局xml插入的主要活动布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mainRoot"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.mistplay.mistplay.MainActivity">
<eightbitlab.com.blurview.BlurView
android:id="@+id/blurView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:blurOverlayColor="#78ffffff">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabGravity="fill"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<include layout="@layout/content_main" />
</eightbitlab.com.blurview.BlurView>
</android.support.design.widget.CoordinatorLayout>
以下是我尝试在MainActivity中模糊屏幕的代码:
@Override
protected void onResume() {
super.onResume();
updateBalanceandCheckTutorial();
if (UserManager.getInstance().getShouldShowTutorial()) {
BlurView blurView = (BlurView) findViewById(R.id.blurView);
final View decorView = getWindow().getDecorView();
final ViewGroup rootView = (ViewGroup) findViewById(R.id.mainRoot);
final Drawable windowBackground = decorView.getBackground();
blurView.setupWith(rootView)
.windowBackground(windowBackground)
.blurAlgorithm(new SupportRenderScriptBlur(this))
.blurRadius(10);
}
}
如果有人能告诉我我做错了什么会非常有帮助。 提前谢谢!