Change height of the snackbar in dotnet MAUI Android

ALEXANDRUSTEFAN CRACEA 0 Reputation points
2024-05-11T10:08:49.3533333+00:00

Hi,

Does anyone know how can i change the height and the padding of the snackbar in dotnet maui Android?

var snackbarOptions = new SnackbarOptions

{


BackgroundColor = Colors.LightGray,

TextColor = Colors.Green,

CornerRadius = new CornerRadius(40),

Font =Microsoft.Maui.Font.SystemFontOfSize(14)
};  
  
  
 var snackbar = Snackbar.Make("text", null, actionButtonText: "", duration: new TimeSpan(0, 0, 3), snackbarOptions);  
  

I want to show a custom message (with a custom background and font), but i want to change the width and padding as well.

Does anyone have a solution?

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,594 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 76,551 Reputation points Microsoft Vendor
    2024-05-13T09:35:31.49+00:00

    Hello,

    You cannot set padding or height in Snackbar from community toolkit.

    But you can popup a Google.Android.Material.Snackbar.Snackbar from native android like following code.

    You can pop up a Google.Android.Material.Snackbar.Snackbar for Android platform and set the padding by layout.SetPadding(); and set height by layout.SetMinimumHeight() like following code.

    #if ANDROID
                Google.Android.Material.Snackbar.Snackbar snackbar = Google.Android.Material.Snackbar.Snackbar.Make(Platform.CurrentActivity, Platform.CurrentActivity.FindViewById(Android.Resource.Id.Content), "Your message", Google.Android.Material.Snackbar.Snackbar.LengthShort); ;
    
    
               Google.Android.Material.Snackbar.Snackbar.SnackbarLayout layout = (Google.Android.Material.Snackbar.Snackbar.SnackbarLayout)snackbar.View;
                layout.SetPadding(150, 0, 0, 0); //your custom padding
                layout.SetMinimumHeight(200);//your custom height
    
                snackbar.Show();
    #endif
    

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  3. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.