How to hide keyboard when focusing Entry

KayKuoKayKuo Member ✭✭✭

I have a Xamarin.forms project, I have a page with an Entry control, I want to hide the keyboard when the Entry gets the focus ,because it is for scanning barcode labels, how can I achieve that?
The following code can implement hidden keyboard, but the keyboard occasionally shows,especially when the entry is empty.
How can I avoid it?thanks
here is my caode :
Control.InputType = 0;
Control.ShowSoftInputOnFocus = false;
InputMethodManager inputMethodManager = Control.Context.GetSystemService(Context.InputMethodService) as InputMethodManager;
inputMethodManager?.HideSoftInputFromWindow(Control.WindowToken, HideSoftInputFlags.None);

Answers

  • Have you tried putting your view inside ScrollView?

    <ScrollView>
    //...Your code
    </ScrollView>
    
  • KayKuoKayKuo Member ✭✭✭

    @LuisDavidDelaCruz sorry,Maybe I don't quite understand what you mean. :'(

  • @KayKuo Use ScrollView
    Like in the example:

    <ContentPage.Content>

    <ScrollView>
    <StackLayout>
    <BoxView BackgroundColor="Red" HeightRequest="600" WidthRequest="150" />
    <Entry />
    </StackLayout>
    </ScrollView>
    

    </ContentPage.Content>

  • KayKuoKayKuo Member ✭✭✭

    @LuisDavidDelaCruz
    thank you,i will try this

  • BushbertBushbert Member ✭✭✭

    I think @LuisDavidDelaCruz misunderstood your question.

    Wrapping it in a scrollview might help if you were wanting to avoid the keyboard overlapping the entry control.

    I can think of a three options.

    1. An entry control is designed to capture text, so it will display a keyboard by default. You could use a custom renderer.

    2. Rather than use an entry why not just use a button. When the user presses the button launch your bar scanning code and set the value to the text property of the button?

    3. Disable the entry control and create a tap event on another container.

      <StackLayout>
          <Entry
              Placeholder="Can Barcode"
              IsEnabled="False"
              x:Name="barcodeno"/>
          <StackLayout.GestureRecognizers>
              <TapGestureRecognizer
                  Tapped="ScanBarcode"
                  NumberOfTapsRequired="1">
              </TapGestureRecognizer>
          </StackLayout.GestureRecognizers>
      </StackLayout>
      
  • JohnHardmanJohnHardman GBUniversity mod

    @KayKuo - Is this using a scanner that populates the Entry with the barcode's textual equivalent?

  • KayKuoKayKuo Member ✭✭✭

    @Bushbert thank you,but we don't need any buttons,when the entry get focus,The scanned data will be filled in entry automatically,so i need to hide the soft keyboard

  • KayKuoKayKuo Member ✭✭✭
  • KayKuoKayKuo Member ✭✭✭

    @LuisDavidDelaCruz thank you,But this is not what I need

  • gmahulegmahule Member ✭✭

    @KayKuo did you find the solution for this I tried using your solution for ScanBarcodeEntry but it is using Windows.UI.Xaml.Controls and I am using Xamarin.forms.xaml so I am facing Incompatibility issues. Please help @KayKuo.

    Thanks.

  • gmahulegmahule Member ✭✭

    @KayKuo I have seen your solution but it is only for Android I am building a UWP application Target version window 10, version 1809, Xamarin.Forms version 3.5.0.169047 and I am running app on tablet.

  • KayKuoKayKuo Member ✭✭✭

    @gmahule said:
    @KayKuo I have seen your solution but it is only for Android I am building a UWP application Target version window 10, version 1809, Xamarin.Forms version 3.5.0.169047 and I am running app on tablet.

    I am sorry for that ,I haven't written an application for UWP yet.

Sign In or Register to comment.