Skip to content

Commit 5f6fbcd

Browse files
committed
fix android stroke
1 parent 2d2bc4c commit 5f6fbcd

File tree

5 files changed

+48
-38
lines changed

5 files changed

+48
-38
lines changed

SampleApp/Resources/Images/sakura.jpg

184 KB
Loading

SampleApp/SampleApp.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
<MauiIcon Include="Resources\appicon.svg" ForegroundFile="Resources\appiconfg.svg" Color="#512BD4" />
3333
<MauiSplashScreen Include="Resources\appiconfg.svg" Color="#512BD4" BaseSize="128,128" />
3434
<MauiFont Include="Resources\Fonts\*" />
35+
<MauiImage Include="Resources\Images\*" />
3536
</ItemGroup>
3637

3738
<ItemGroup>

SampleApp/Views/MainPage.xaml

+42-29
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,55 @@
44
xmlns:stroked="https://vapolia.eu/Vapolia.StrokedLabel"
55
x:Class="SampleApp.Views.MainPage"
66
Title="Stroked Labels Demo">
7+
<Page.Resources>
8+
<Style TargetType="Label">
9+
<Setter Property="TextColor" Value="LightBlue" />
10+
<Setter Property="stroked:StrokedLabel.StrokeColor" Value="DarkBlue" />
11+
<Setter Property="stroked:StrokedLabel.StrokeWidth" Value="4" />
12+
</Style>
13+
</Page.Resources>
714

815
<ScrollView>
9-
<Grid RowDefinitions="*,40">
10-
11-
<StackLayout Padding="30" Spacing="25">
12-
<StackLayout.Resources>
13-
<Style TargetType="Label">
14-
<Setter Property="stroked:StrokedLabel.StrokeColor" Value="Blue" />
15-
<Setter Property="stroked:StrokedLabel.StrokeWidth" Value="4" />
16-
</Style>
17-
</StackLayout.Resources>
16+
<StackLayout Padding="30" Spacing="25">
1817

19-
<Label FontSize="32" HorizontalOptions="Center"
20-
Style="{StaticResource MauiLabel}"
21-
stroked:StrokedLabel.StrokeColor="Blue"
22-
stroked:StrokedLabel.StrokeWidth="4"
23-
Text="Hello, World!" />
18+
<Label FontSize="32"
19+
HorizontalOptions="Center"
20+
Text="I like stoked labels!" />
2421

25-
<Label FontSize="18" HorizontalOptions="Center"
26-
Style="{StaticResource MauiLabel}"
27-
stroked:StrokedLabel.StrokeColor="Green"
28-
stroked:StrokedLabel.StrokeWidth="4"
29-
Text="Welcome to .NET Multi-platform App UI" />
22+
<Grid>
23+
<Image Source="sakura.jpg" Aspect="AspectFit" />
24+
25+
<Label FontSize="40"
26+
HorizontalTextAlignment="Center"
27+
VerticalOptions="Center"
28+
TextColor="Aquamarine"
29+
stroked:StrokedLabel.StrokeColor="Black"
30+
stroked:StrokedLabel.StrokeWidth="4"
31+
Text="Stroked text is much more readable when over a background image" />
32+
</Grid>
3033

31-
<Label x:Name="CounterLabel" FontAttributes="Bold" FontSize="18" HorizontalOptions="Center"
32-
Style="{StaticResource MauiLabel}"
33-
Text="Current count: 0" />
34+
<Label FontSize="20"
35+
HorizontalTextAlignment="Center"
36+
TextColor="DarkRed"
37+
stroked:StrokedLabel.StrokeColor="Red"
38+
stroked:StrokedLabel.StrokeWidth="1"
39+
Text="Stroked text can be emphasized without needing bold" />
3440

35-
</StackLayout>
41+
<Label FontSize="24"
42+
HorizontalTextAlignment="Center"
43+
TextColor="LightGoldenrodYellow"
44+
stroked:StrokedLabel.StrokeColor="LightCoral"
45+
stroked:StrokedLabel.StrokeWidth="1"
46+
Text="It can also glow with a shadow!">
47+
<Label.Shadow>
48+
<Shadow Brush="Red"
49+
Offset="0,0"
50+
Radius="2"
51+
Opacity="0.8" />
52+
</Label.Shadow>
53+
</Label>
3654

37-
<Grid Grid.Row="1" BackgroundColor="{AppThemeBinding Dark={StaticResource BackgroundDark}, Light={StaticResource Primary}}">
38-
<Label x:Name="VersionLabel" HorizontalOptions="Center" VerticalOptions="Center"
39-
TextColor="{StaticResource White}" />
40-
</Grid>
41-
42-
</Grid>
55+
</StackLayout>
4356
</ScrollView>
4457

4558
</ContentPage>

SampleApp/Views/MainPage.xaml.cs

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
using System.Reflection;
2-
3-
namespace SampleApp.Views;
1+
namespace SampleApp.Views;
42

53
public partial class MainPage
64
{
75
public MainPage()
86
{
97
InitializeComponent();
10-
var version = typeof(MauiApp).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
11-
VersionLabel.Text = $".NET MAUI ver. {version?[..version.IndexOf('+')]}";
128
}
139
}

Vapolia.StrokedLabels/StrokedLabelInternals.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,6 @@ protected override void OnDraw(Canvas canvas)
148148

149149
if (p != null)
150150
{
151-
//Draw the inside
152-
p.SetStyle(Android.Graphics.Paint.Style.Fill);
153-
base.OnDraw(canvas);
154-
155151
//save the text color
156152
var currentTextColor = CurrentTextColor;
157153

@@ -163,6 +159,10 @@ protected override void OnDraw(Canvas canvas)
163159

164160
//restore the text color
165161
SetTextColor(new Android.Graphics.Color(currentTextColor));
162+
163+
//Draw the inside
164+
p.SetStyle(Android.Graphics.Paint.Style.Fill);
165+
base.OnDraw(canvas);
166166
}
167167
}
168168
finally

0 commit comments

Comments
 (0)