Msui android entry focus line issue

asked 2022-12-28T20:56:14.67+00:00
Haviv Elbsz 481 Reputation points

Hi all

Is it possible to show the line in the android entry control
only when the entry get the focus
and to hide it when not

Thank you very much

A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
880 questions
{count} votes

Accepted answer
  1. answered 2022-12-29T08:07:20.493+00:00
    Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 11,061 Reputation points Microsoft Employee


    It is more recommended to hide the underline of entry. Then, you could use a BoxView as the underline of the entry to implement this feature.

    This is because for an element style, it would be better if we could implement it using cross-platform UI classes. This helps maintain the code and facilitates subsequent expansion to other platforms.

    You could refer to the following code sample to implement this feature:

       // First hide the underline of entry via handler:  
       // Call this method in the constructor method of your Page.  
       void ModifyEntry()  
           Microsoft.Maui.Handlers.EntryHandler.Mapper.AppendToMapping("MyCustomization", (handler, view) =>  
       #if ANDROID  
               GradientDrawable gd = new GradientDrawable();  

    Then, you could use the BoxView to draw a underline for the Entry:

       <ContentView Margin="10">  
               <Entry Focused="Entry_Focused" Unfocused="Entry_Unfocused"/>  
               <BoxView x:Name="underline" IsVisible="false" BackgroundColor="Black" HeightRequest="1"/>  

    Finally, you just need to set the visibility of BoxView in focused and unfocused events of the Entry, like underline.IsVisible = false;.

    Best Regards,

    Alec Liu.

    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.

0 additional answers

Sort by: Most helpful