Xamarin Forms FAB Icon Suddenly Squeezes
up vote
0
down vote
favorite
I have upgraded from Xamarin Forms 2.5 to 3.4 and I started getting a FAB button issue on Android only. The button appears right for the first time, but when I push and pop few times (on top of the page containing the button), the button suddenly shrinks around 40%
Here is my renderer code:
using Xamarin.Forms;
namespace MyApp.SLayout
{
[Preserve(AllMembers = true)]
public class SFloatingActionButton : Button
{
public static BindableProperty ButtonColorProperty = BindableProperty.Create(nameof(ButtonColor), typeof(Color),
typeof(SFloatingActionButton), Color.Accent);
public Color ButtonColor
{
get => (Color) GetValue(ButtonColorProperty);
set => SetValue(ButtonColorProperty, value);
}
}
}
using System;
using Android.Content;
using Android.Content.Res;
using Android.Graphics;
using Android.Runtime;
using Android.Support.V4.View;
using FFImageLoading;
using MyApp.Droid.SLayout;
using MyApp.SLayout;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using FAB = Android.Support.Design.Widget.FloatingActionButton;
[assembly: ExportRenderer(typeof(SFloatingActionButton), typeof(FloatingActionButtonRenderer))]
namespace MyApp.Droid.SLayout
{
[Preserve(AllMembers = true)]
public class FloatingActionButtonRenderer : Xamarin.Forms.Platform.Android.AppCompat.ViewRenderer<SFloatingActionButton, FAB>
{
private readonly Context _context;
private FAB _fab;
private Bitmap _img;
public FloatingActionButtonRenderer(Context context) : base(context)
{
_context = context;
}
protected override void OnElementChanged(ElementChangedEventArgs<SFloatingActionButton> e)
{
base.OnElementChanged(e);
if (Control == null)
{
// Instantiate the native control
_fab = new FAB(_context);
ViewCompat.SetBackgroundTintList(_fab, ColorStateList.ValueOf(Element.ButtonColor.ToAndroid()));
_fab.UseCompatPadding = true;
string imageFile = Element.Image.File;
string drawableNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(imageFile)?.ToLower();
int imageResourceName = _context.Resources.GetIdentifier(drawableNameWithoutExtension, "drawable", _context.PackageName);
_img = BitmapFactory.DecodeResource(_context.Resources, imageResourceName);
_fab.SetImageBitmap(_img);
SetNativeControl(_fab);
}
if (e.OldElement != null)
{
_img?.TryDispose();
_fab.Click -= Fab_Click;
}
if (e.NewElement != null)
{
_fab.Click += Fab_Click;
}
}
protected override void OnLayout(bool changed, int l, int t, int r, int b)
{
base.OnLayout(changed, l, t, r, b);
Control.BringToFront();
}
private void Fab_Click(object sender, EventArgs e)
{
// proxy the click to the element
((IButtonController) Element).SendClicked();
}
}
}
c# xamarin.forms fab custom-renderer
add a comment |
up vote
0
down vote
favorite
I have upgraded from Xamarin Forms 2.5 to 3.4 and I started getting a FAB button issue on Android only. The button appears right for the first time, but when I push and pop few times (on top of the page containing the button), the button suddenly shrinks around 40%
Here is my renderer code:
using Xamarin.Forms;
namespace MyApp.SLayout
{
[Preserve(AllMembers = true)]
public class SFloatingActionButton : Button
{
public static BindableProperty ButtonColorProperty = BindableProperty.Create(nameof(ButtonColor), typeof(Color),
typeof(SFloatingActionButton), Color.Accent);
public Color ButtonColor
{
get => (Color) GetValue(ButtonColorProperty);
set => SetValue(ButtonColorProperty, value);
}
}
}
using System;
using Android.Content;
using Android.Content.Res;
using Android.Graphics;
using Android.Runtime;
using Android.Support.V4.View;
using FFImageLoading;
using MyApp.Droid.SLayout;
using MyApp.SLayout;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using FAB = Android.Support.Design.Widget.FloatingActionButton;
[assembly: ExportRenderer(typeof(SFloatingActionButton), typeof(FloatingActionButtonRenderer))]
namespace MyApp.Droid.SLayout
{
[Preserve(AllMembers = true)]
public class FloatingActionButtonRenderer : Xamarin.Forms.Platform.Android.AppCompat.ViewRenderer<SFloatingActionButton, FAB>
{
private readonly Context _context;
private FAB _fab;
private Bitmap _img;
public FloatingActionButtonRenderer(Context context) : base(context)
{
_context = context;
}
protected override void OnElementChanged(ElementChangedEventArgs<SFloatingActionButton> e)
{
base.OnElementChanged(e);
if (Control == null)
{
// Instantiate the native control
_fab = new FAB(_context);
ViewCompat.SetBackgroundTintList(_fab, ColorStateList.ValueOf(Element.ButtonColor.ToAndroid()));
_fab.UseCompatPadding = true;
string imageFile = Element.Image.File;
string drawableNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(imageFile)?.ToLower();
int imageResourceName = _context.Resources.GetIdentifier(drawableNameWithoutExtension, "drawable", _context.PackageName);
_img = BitmapFactory.DecodeResource(_context.Resources, imageResourceName);
_fab.SetImageBitmap(_img);
SetNativeControl(_fab);
}
if (e.OldElement != null)
{
_img?.TryDispose();
_fab.Click -= Fab_Click;
}
if (e.NewElement != null)
{
_fab.Click += Fab_Click;
}
}
protected override void OnLayout(bool changed, int l, int t, int r, int b)
{
base.OnLayout(changed, l, t, r, b);
Control.BringToFront();
}
private void Fab_Click(object sender, EventArgs e)
{
// proxy the click to the element
((IButtonController) Element).SendClicked();
}
}
}
c# xamarin.forms fab custom-renderer
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have upgraded from Xamarin Forms 2.5 to 3.4 and I started getting a FAB button issue on Android only. The button appears right for the first time, but when I push and pop few times (on top of the page containing the button), the button suddenly shrinks around 40%
Here is my renderer code:
using Xamarin.Forms;
namespace MyApp.SLayout
{
[Preserve(AllMembers = true)]
public class SFloatingActionButton : Button
{
public static BindableProperty ButtonColorProperty = BindableProperty.Create(nameof(ButtonColor), typeof(Color),
typeof(SFloatingActionButton), Color.Accent);
public Color ButtonColor
{
get => (Color) GetValue(ButtonColorProperty);
set => SetValue(ButtonColorProperty, value);
}
}
}
using System;
using Android.Content;
using Android.Content.Res;
using Android.Graphics;
using Android.Runtime;
using Android.Support.V4.View;
using FFImageLoading;
using MyApp.Droid.SLayout;
using MyApp.SLayout;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using FAB = Android.Support.Design.Widget.FloatingActionButton;
[assembly: ExportRenderer(typeof(SFloatingActionButton), typeof(FloatingActionButtonRenderer))]
namespace MyApp.Droid.SLayout
{
[Preserve(AllMembers = true)]
public class FloatingActionButtonRenderer : Xamarin.Forms.Platform.Android.AppCompat.ViewRenderer<SFloatingActionButton, FAB>
{
private readonly Context _context;
private FAB _fab;
private Bitmap _img;
public FloatingActionButtonRenderer(Context context) : base(context)
{
_context = context;
}
protected override void OnElementChanged(ElementChangedEventArgs<SFloatingActionButton> e)
{
base.OnElementChanged(e);
if (Control == null)
{
// Instantiate the native control
_fab = new FAB(_context);
ViewCompat.SetBackgroundTintList(_fab, ColorStateList.ValueOf(Element.ButtonColor.ToAndroid()));
_fab.UseCompatPadding = true;
string imageFile = Element.Image.File;
string drawableNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(imageFile)?.ToLower();
int imageResourceName = _context.Resources.GetIdentifier(drawableNameWithoutExtension, "drawable", _context.PackageName);
_img = BitmapFactory.DecodeResource(_context.Resources, imageResourceName);
_fab.SetImageBitmap(_img);
SetNativeControl(_fab);
}
if (e.OldElement != null)
{
_img?.TryDispose();
_fab.Click -= Fab_Click;
}
if (e.NewElement != null)
{
_fab.Click += Fab_Click;
}
}
protected override void OnLayout(bool changed, int l, int t, int r, int b)
{
base.OnLayout(changed, l, t, r, b);
Control.BringToFront();
}
private void Fab_Click(object sender, EventArgs e)
{
// proxy the click to the element
((IButtonController) Element).SendClicked();
}
}
}
c# xamarin.forms fab custom-renderer
I have upgraded from Xamarin Forms 2.5 to 3.4 and I started getting a FAB button issue on Android only. The button appears right for the first time, but when I push and pop few times (on top of the page containing the button), the button suddenly shrinks around 40%
Here is my renderer code:
using Xamarin.Forms;
namespace MyApp.SLayout
{
[Preserve(AllMembers = true)]
public class SFloatingActionButton : Button
{
public static BindableProperty ButtonColorProperty = BindableProperty.Create(nameof(ButtonColor), typeof(Color),
typeof(SFloatingActionButton), Color.Accent);
public Color ButtonColor
{
get => (Color) GetValue(ButtonColorProperty);
set => SetValue(ButtonColorProperty, value);
}
}
}
using System;
using Android.Content;
using Android.Content.Res;
using Android.Graphics;
using Android.Runtime;
using Android.Support.V4.View;
using FFImageLoading;
using MyApp.Droid.SLayout;
using MyApp.SLayout;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using FAB = Android.Support.Design.Widget.FloatingActionButton;
[assembly: ExportRenderer(typeof(SFloatingActionButton), typeof(FloatingActionButtonRenderer))]
namespace MyApp.Droid.SLayout
{
[Preserve(AllMembers = true)]
public class FloatingActionButtonRenderer : Xamarin.Forms.Platform.Android.AppCompat.ViewRenderer<SFloatingActionButton, FAB>
{
private readonly Context _context;
private FAB _fab;
private Bitmap _img;
public FloatingActionButtonRenderer(Context context) : base(context)
{
_context = context;
}
protected override void OnElementChanged(ElementChangedEventArgs<SFloatingActionButton> e)
{
base.OnElementChanged(e);
if (Control == null)
{
// Instantiate the native control
_fab = new FAB(_context);
ViewCompat.SetBackgroundTintList(_fab, ColorStateList.ValueOf(Element.ButtonColor.ToAndroid()));
_fab.UseCompatPadding = true;
string imageFile = Element.Image.File;
string drawableNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(imageFile)?.ToLower();
int imageResourceName = _context.Resources.GetIdentifier(drawableNameWithoutExtension, "drawable", _context.PackageName);
_img = BitmapFactory.DecodeResource(_context.Resources, imageResourceName);
_fab.SetImageBitmap(_img);
SetNativeControl(_fab);
}
if (e.OldElement != null)
{
_img?.TryDispose();
_fab.Click -= Fab_Click;
}
if (e.NewElement != null)
{
_fab.Click += Fab_Click;
}
}
protected override void OnLayout(bool changed, int l, int t, int r, int b)
{
base.OnLayout(changed, l, t, r, b);
Control.BringToFront();
}
private void Fab_Click(object sender, EventArgs e)
{
// proxy the click to the element
((IButtonController) Element).SendClicked();
}
}
}
c# xamarin.forms fab custom-renderer
c# xamarin.forms fab custom-renderer
asked Nov 22 at 3:34
Adam
1,38511638
1,38511638
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
Xamarin.Forms 2.5 is a very old version, with many changes since 3.0.Here is a demo that you can refer.(This should be a comment, but my reputation is less than 50).
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Xamarin.Forms 2.5 is a very old version, with many changes since 3.0.Here is a demo that you can refer.(This should be a comment, but my reputation is less than 50).
add a comment |
up vote
0
down vote
Xamarin.Forms 2.5 is a very old version, with many changes since 3.0.Here is a demo that you can refer.(This should be a comment, but my reputation is less than 50).
add a comment |
up vote
0
down vote
up vote
0
down vote
Xamarin.Forms 2.5 is a very old version, with many changes since 3.0.Here is a demo that you can refer.(This should be a comment, but my reputation is less than 50).
Xamarin.Forms 2.5 is a very old version, with many changes since 3.0.Here is a demo that you can refer.(This should be a comment, but my reputation is less than 50).
answered Nov 23 at 6:55
Akai Rika
245
245
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53423506%2fxamarin-forms-fab-icon-suddenly-squeezes%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown