Is there support for SearchBar on nougat 7.0?

Uploaded a build to test cloud which passed on multiple devices and android versions. However the 7.0 device failed because the screen didn't render my search bar.

    <ContentPage.Content>
        <StackLayout Orientation="Vertical" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
            <StackLayout.Padding>
                <Thickness>
                    4, 0, 4, 0
                </Thickness>
            </StackLayout.Padding>

            <SearchBar x:Name="txtSearch">
            </SearchBar>

            <ListView x:Name="listCountries">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ImageCell Text="{Binding description}" TextColor="Black" ImageSource="{Binding flag, Converter={StaticResource base64ToImageSource}}" />
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
        </StackLayout>
    </ContentPage.Content>

SearchBar simply did not appear on the screen of the 7.0 device (specifically, LG Nexus 5X running Android 7.0). Is this an issue with the OS or with XF?

I've attached some images - one is a working example on a 6.0.1 device, the other shows the missing searchbar on 7.0.

Thanks,

JWF

Posts

  • JordanWeber-FlinkJordanWeber-Flink USUniversity ✭✭

    Apparently I'm not the only one. Kasper submitted this bug three weeks ago: https://bugzilla.xamarin.com/show_bug.cgi?id=44171

    Kasper says the bug is caused by a second element in the stack with expanding layout (in my case, the list view). Given that having a search bar on a screen is a basic, widespread requirement for virtually every app using Xamarin, and that 7.0 is rolling out to phones as we speak, I hope this bug gets some attention.

  • Ed_SEd_S NLMember ✭✭

    Exactly the same problem here.

  • EmanueleSabettaEmanueleSabetta ITBeta ✭✭✭

    I have the same problem. This needs to be addressed asap.

  • PaulDiPietroPaulDiPietro USXamarin Team Xamurai

    @JordanWeber-Flink / @Ed_S / @EmanueleSabetta :

    This appears to be occurring due to an issue that currently exists in v24; it has been reported and acknowledged here:

    https://code.google.com/p/android/issues/detail?id=221304

  • JordanWeber-FlinkJordanWeber-Flink USUniversity ✭✭

    Paul - thanks for the update. To your knowledge is there a workaround? Something we can put in a platform renderer?

  • JordanWeber-FlinkJordanWeber-Flink USUniversity ✭✭

    @PaulDiPietro - thank you very much. I have verified that your sample code causes the search bar to appear correctly on a Motorola Nexus 6 running a preview of Android N. For the record, I set the height request to 50.

  • CostaCarterCostaCarter USMember

    Also can confirm. Still an issue.

  • As Aaron said, after adding a HeightRequest workaround it worked!

  • CarlosScarattiCarlosScaratti USMember ✭✭

    @AndyMartin.6838 said:
    I set it to 40.0 to get around the bug. Does anyone know what the height it is supposed to be?

    if(Device.RuntimePlatform == Device.Android)
    {
      //Fixes an android bug where the search bar would be hidden
      mSearchBar.HeightRequest = 40.0;
    }
    

    Thank you it worked well

  • VH5150VH5150 GBMember ✭✭

    Thanks for the workaround it works well \O/

  • batmacibatmaci DEMember ✭✭✭✭✭
    edited September 2017

    Google still didnt fix this problem? Is it good solution to hardcode heighrequest as 40 because of different devices with different screen size?

  • JamesClossJamesCloss GBMember ✭✭

    Dang I'm glad I found this thread, now I know why some users can't find the search on my app!

    I measured the searchbar on a different Android version and the height was 45 so that's what I'm using.

    Workaround works great though - thanks!

  • Hey guys... Just found this error in one of my apps...
    Here are a custom renderer.. Just add this on you android project :smile:
    And every searchBar will appear.
    Note: If you already use a Custom Renderer for searchbar you have just to add the heightRequest on it.

        using System;
        using Android.OS;
        using App.Droid;
        using Xamarin.Forms;
        using Xamarin.Forms.Platform.Android;
    
    
        // WorkAround to searchBar not appearing in newer android versions
        [assembly: ExportRenderer(typeof(SearchBar), typeof(CustomSearchBarRenderer))]
        namespace App.Droid
        {
            public class CustomSearchBarRenderer : SearchBarRenderer
            {
                public CustomSearchBarRenderer()
                {
                }
    
                protected override void OnElementChanged(ElementChangedEventArgs<SearchBar> e)
                {
                    base.OnElementChanged(e);
    
                    if (e.OldElement != null || Element == null)
                        return;
    
                    if(Build.VERSION.SdkInt >= BuildVersionCodes.N)
                         Element.HeightRequest = 40;
                }
            }
        }
    
  • AmjadAli.0364AmjadAli.0364 USMember ✭✭

    @CarlosScaratti said:

    @AndyMartin.6838 said:
    I set it to 40.0 to get around the bug. Does anyone know what the height it is supposed to be?

    if(Device.RuntimePlatform == Device.Android)
    {
        //Fixes an android bug where the search bar would be hidden
        mSearchBar.HeightRequest = 40.0;
    }
    

    Thank you it worked well

    Thanks worked fine

  • I got the same problem for android nougat and solve that by setting HeightRequest.

  • Oracle22Oracle22 USMember ✭✭
    edited January 2018
    <SearchBar x:Name="searchbar" HeightRequest="25" FontAttributes="Bold" FontSize="Medium" Placeholder="Rechercher" PlaceholderColor="#1d5ca5" TextColor="#1d5ca5" Margin="0,25,0,25"  />
    

    Add HeightRequest="25"

  • Sa1Sa1 USMember ✭✭

    @RaphaelChiorlinRanieri, I think in your answer it should be

    if(Build.VERSION.SdkInt == BuildVersionCodes.N)

  • @Sa1 The problem was happening in every version after Android N, so it should be for Android N version and Bigger than it.
    This is why I used >=

  • Sa1Sa1 USMember ✭✭

    @RaphaelChiorlinRanieri I examined the search bar on 7.1 and above and the search bar was shown.
    The problem exists just with the SDK 24.

  • VipinKrishnaVipinKrishna Member ✭✭
    Searchbar was not working on my redmi note 4 android 7.0.. solved by adding height request
  • @AdamCardenas said:
    Confirmed the following. No need for custom renderer.

    Does not work; missing HeightRequest

    <SearchBar x:Name="Query"
                            Placeholder="Search"
                            SearchButtonPressed="OnButtonClick"
                            TextChanged="OnTextChanged"
                            />
    

    Does work, notice the HeightRequest

    <SearchBar x:Name="Query"
                            Placeholder="Search"
                            SearchButtonPressed="OnButtonClick"
                            TextChanged="OnTextChanged"
                            HeightRequest="50" />
    

    It works ,thanks.

  • AmmaarAmmaar Member ✭✭
    edited April 2018

    Confirming that this is still the issue, the search bar is showing with height request but hard coding will create an issue on devices with different dimensions I wonder why isn't it fixed until yet.

    Xiomi Redmi note 4 (Android 7.0, API 24).
    Solved by adding height request of 42 units.

  • AwadhendraAwadhendra Member ✭✭

    Android 7.0 and 7.1 Search bar appears first time after installation once I logout or changes the orientation to landscape mode its gone, Have implemented this code as well.

     protected override void OnElementChanged(ElementChangedEventArgs<SearchBar> e)
                {
                    base.OnElementChanged(e);
    
                    if (e.OldElement != null || Element == null)
                        return;
    
                    if(Build.VERSION.SdkInt >= BuildVersionCodes.N)
                         Element.HeightRequest = 40;
                }
    
  • AhmedAbubakarAhmedAbubakar USMember ✭✭

    @AdamCardenas this XAML works cheers :):)

Sign In or Register to comment.