Search code examples
androidxamlxamarin.android.net-maui

MAUI android rendering page


I am starting using the visual studio 2022 v. 17.3 preview 2 In the startup program that shows the dotnet_bot image and a button with text " Click Me"

now when you click the button text will change to "Clicked 15 times" ( number change accoring to count value according the following code:

private void OnCounterClicked(object sender, EventArgs e)
{
        count++;

        if (count == 1)
            CounterBtn.Text = $"Clicked {count} time";
        else
            CounterBtn.Text = $"Clicked {count} times";
        
        SemanticScreenReader.Announce(CounterBtn.Text);
    }

so the text will change but the button size will not adjust .. and the text will be clipped as the following image:

enter image description here

I tried to search online and on github and microsoft documentation.. I couldn't find out how to force the button to adjust its size to the text property

This happen only in Android but not in windows

I tested android phone emulator (Pixel 5 API 30 (Android 11.0 ) Same behavior on android tablet (Tablet M-DPI 10.1in - API 31 ( android 12)

The solution I found which is not accepted is

to use any entry element that will make the keyboard pop out.. then and only then the page will re-render and the button will expand to show the full text "clicked 15 times"

So my question is :

What am I missing here? How to force the page to rerender? Or is it a bug in MAUI ??


Solution

  • Update

    Yes,it is a known issue in android.

    You can follow it up here:

    https://github.com/dotnet/maui/pull/8136

    https://github.com/dotnet/maui/issues/8028

    But as a workaround,you can try to change the property of Button CounterBtn from

    HorizontalOptions="Center"
    

    To

    HorizontalOptions="Fill" 
    

    or

    HorizontalOptions="FillAndExpand"