Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Android SearchBar with height less than 65 text cut off

$
0
0

I have found an issue in the Android SearchBar, if the height is less than 65 it doesn't center the text vertically and depending on how small you make the SearchBar height it will cut off the top of the text.

After an hour or two of fighting with a custom renderer I have found some OnLayout changes that fix the problem for me and I wanted to share in case anyone else runs across this issue.

What I found is that the top and height of the AutoCompleteTextView within the SearchBar is not adjusted to match the height of the SearchBar when set is XAML. The following custom renderer code resolves the issue for me:

        protected override void OnLayout(bool changed, int l, int t, int r, int b)
        {
            base.OnLayout(changed, l, t, r, b);
            var linLayout = (LinearLayout)Control.GetChildAt(0);
            //var searchTextView = (TextView)linLayout.GetChildAt(0);
            //var searchButton = (ImageView)linLayout.GetChildAt(1);

            var searchEditFrame = (LinearLayout)linLayout.GetChildAt(2);
            //var searchMagIcon = (ImageView) searchEditFrame.GetChildAt(0);

            var searchPlate = (LinearLayout)searchEditFrame.GetChildAt(1);
            var searchSrcText = (AutoCompleteTextView)searchPlate.GetChildAt(0);
            searchSrcText.SetHeight(Control.Height);
            searchSrcText.Top = 0;
            //var searchCloseButton = (ImageView) searchPlate.GetChildAt(1);

            //var submitArea = (LinearLayout)searchEditFrame.GetChildAt(2);
            //var searchGoButton = (ImageView) submitArea.GetChildAt(0);
            //var searchVoiceButton = (ImageView) submitArea.GetChildAt(1);
        }

Hopefully this code helps someone along the way. I have commented out but left in the other elements of the SearchBar, maybe someone will find those helpful at some point to.

Thanks
M


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>