Skip to content
This repository was archived by the owner on Mar 26, 2025. It is now read-only.

Commit 50c71e4

Browse files
committed
Add blur library for android
1 parent 9f0983b commit 50c71e4

File tree

4 files changed

+87
-0
lines changed

4 files changed

+87
-0
lines changed

samples/BlurViewFormsSample/BlurViewFormsSample/BlurViewFormsSample.Android/BlurViewFormsSample.Android.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
<Reference Include="System.Xml" />
4949
</ItemGroup>
5050
<ItemGroup>
51+
<PackageReference Include="Xamarin.BlurView">
52+
<Version>1.3.4</Version>
53+
</PackageReference>
5154
<PackageReference Include="Xamarin.Forms" Version="3.0.0.482510" />
5255
<PackageReference Include="Xamarin.Android.Support.Design" Version="27.0.2" />
5356
<PackageReference Include="Xamarin.Android.Support.v7.AppCompat" Version="27.0.2" />
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using Android.App;
2+
using Android.Content;
3+
using Android.Views;
4+
using Android.Widget;
5+
6+
using Xamarin.Forms;
7+
using Xamarin.Forms.Platform.Android;
8+
9+
using Com.EightbitLab.BlurViewBinding;
10+
11+
using BlurViewFormsSample;
12+
using BlurViewFormsSample.Droid;
13+
14+
[assembly: ExportRenderer(typeof(FormsBlurView), typeof(FormsBlurViewRenderer))]
15+
16+
namespace BlurViewFormsSample.Droid
17+
{
18+
public class FormsBlurViewRenderer : ViewRenderer<FormsBlurView, FrameLayout>
19+
{
20+
public FormsBlurViewRenderer(Context context) : base(context)
21+
{
22+
}
23+
24+
protected override void OnElementChanged(ElementChangedEventArgs<FormsBlurView> e)
25+
{
26+
base.OnElementChanged(e);
27+
28+
if (Control == null)
29+
{
30+
var context = Context;
31+
var activity = context as Activity;
32+
33+
var rootView = (ViewGroup) activity.Window.DecorView.FindViewById(Android.Resource.Id.Content);
34+
var windowBackground = activity.Window.DecorView.Background;
35+
36+
var blurView = new BlurView(context);
37+
38+
blurView.SetOverlayColor(Resource.Color.colorOverlay);
39+
40+
blurView.SetupWith(rootView)
41+
.WindowBackground(windowBackground)
42+
.BlurAlgorithm(new RenderScriptBlur(context))
43+
.BlurRadius(10f);
44+
45+
SetNativeControl(blurView);
46+
}
47+
}
48+
}
49+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
using Xamarin.Forms;
7+
8+
namespace BlurViewFormsSample
9+
{
10+
public class FormsBlurView : StackLayout
11+
{
12+
13+
}
14+
}

samples/BlurViewFormsSample/BlurViewFormsSample/BlurViewFormsSample/MainPage.xaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,26 @@
44
xmlns:local="clr-namespace:BlurViewFormsSample"
55
x:Class="BlurViewFormsSample.MainPage">
66

7+
<ScrollView>
8+
<StackLayout BackgroundColor="Red">
9+
<Label Text="Welcome to Xamarin.Forms!" HorizontalOptions="Center" VerticalOptions="CenterAndExpand" />
10+
11+
<local:FormsBlurView HeightRequest="100">
12+
<Label Text="Test Text" />
13+
<Button Text="Click me!" />
14+
</local:FormsBlurView>
15+
16+
<BoxView BackgroundColor="Blue" HeightRequest="100" />
17+
<BoxView BackgroundColor="Blue" HeightRequest="100" />
18+
<BoxView BackgroundColor="Blue" HeightRequest="100" />
19+
<BoxView BackgroundColor="Blue" HeightRequest="100" />
20+
<BoxView BackgroundColor="Blue" HeightRequest="100" />
21+
<BoxView BackgroundColor="Blue" HeightRequest="100" />
22+
<BoxView BackgroundColor="Blue" HeightRequest="100" />
23+
<BoxView BackgroundColor="Blue" HeightRequest="100" />
24+
<BoxView BackgroundColor="Blue" HeightRequest="100" />
25+
<BoxView BackgroundColor="Blue" HeightRequest="100" />
26+
</StackLayout>
27+
</ScrollView>
728

829
</ContentPage>

0 commit comments

Comments
 (0)