How to change background color for maui searchbar and stepper

Haviv Elbsz 1,751 Reputation points
2023-01-15T08:00:50.9333333+00:00

Hello all the searchbar and stepper have no properties for background color. Is there a way to change background color for them. Thank you

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

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 64,006 Reputation points Microsoft Vendor
    2023-01-16T02:21:22.8233333+00:00

    Hello,

    Is there a way to change background color for them

    Yes.

    • For Searchbar, please open the Resources\Styles\Styles.xaml file, then find the <Style TargetType="SearchBar"> tag, change the value of <Setter Property="BackgroundColor" Value="Green" />, I set the green for testing.

    ====================Update======================

    • For Stepper, you can change the background color by Handler. Change the Button's background color by linearLayout.GetChildAt(0).SetBackgroundColor(Android.Graphics.Color.Red);.
       Microsoft.Maui.Handlers.StepperHandler.Mapper.AppendToMapping("MyCustomization", (handler, view) =>
            {
    #if ANDROID
                 Android.Widget.LinearLayout linearLayout= handler.PlatformView as Android.Widget.LinearLayout;
                linearLayout.GetChildAt(0).SetBackgroundColor(Android.Graphics.Color.Red);
                linearLayout.GetChildAt(1).SetBackgroundColor(Android.Graphics.Color.Red);
    #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.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful