Icon to Hide Keyboard

IOS doesn´t have a key to hide the keyboard.

I show how to add a icon to hide the keyboard.

I hope it´s usefull to someone
 

Attachments

  • hide_keyboard.zip
    4.1 KB · Views: 362

stanmiller

Active Member
Licensed User
Longtime User
This is a great contribution!

Using an inputAccessoryView is not well known and should get more coverage around here. We use the technique to add [Prev] [Next] and [Done] buttons to navigate through edit fields in our projects.

Here's a couple screenshots of your project at work:

1_hidekey_portrait_zpseewsqdkz.jpg


2_hidekey_landscape_zpsh38o0ygp.jpg


There is one edit I would suggest. When adding views by code the B4i guide recommends they be attached while inside the Page_Resize event. This is because %x and %y ( page width and height ) values are unknown prior.

B4i Beginner's Guide, Page 152

1_hidekey_addview_page_resize_zpsezyofxwo.jpg


Here's an updated version of the code. I moved attaching the views to AddViewsByCode.
B4X:
Sub Process_Globals
   Public App As Application
   Public NavControl As NavigationController
   Private Page1 As Page
   Dim tf, tf1  As TextField
   Dim  tf2, tf3 As TextView
   Dim gWidth As Int
   Dim gPnl_Hide As Panel
   Dim gIm_Hide As ImageView

End Sub

Private Sub Page1_Resize(Width As Int, Height As Int)
    gWidth = 100%x
    gPnl_Hide.RemoveAllViews
    AddViewsByCode
End Sub

Private Sub Application_Start (Nav As NavigationController)
   NavControl = Nav
   Page1.Initialize("Page1")
   Page1.Title = "Page 1"
   Page1.RootPanel.Color = Colors.White
   NavControl.ShowPage(Page1)

   tf.Initialize("tf")
   tf.Text = "text 1"

   tf1.Initialize("tf")
   tf1.Text = "text 2"

   tf2.Initialize("tf")
   tf2.KeyboardType = tf2.TYPE_NUMBER_PAD
   tf2.Text = "text 3"

   tf3.Initialize("tf")
   tf3.Text = "text 4"

   gIm_Hide.Initialize("Im_Hide")
   gIm_Hide.Bitmap = LoadBitmap(File.DirAssets, "hide_keyboard.png")
   gIm_Hide.Height = 50
   gIm_Hide.Width = 40

   gPnl_Hide.Initialize ("")
   gPnl_Hide.Color = Colors.Transparent
   gPnl_Hide.Height = 40


'  Page1.RootPanel.AddView ( gIm_Hide, 230,0,50,50)

End Sub

Sub Im_Hide_Click
    Page1.ResignFocus
End Sub

Sub AddViewToKeyboard (TextField1 As Object)
   Dim no As NativeObject = TextField1
   no.SetField("inputAccessoryView", gPnl_Hide)
End Sub


Sub AddViewsByCode

    Page1.RootPanel.AddView(tf, 0, 0, 200, 50)
    Page1.RootPanel.AddView(tf1, 0, 50, 200, 50)
    Page1.RootPanel.AddView(tf2, 0, 100, 200, 50)
    Page1.RootPanel.AddView(tf3, 0, 150, 200, 50)
    gPnl_Hide.AddView ( gIm_Hide, gWidth-55,0,50,40)

    AddViewToKeyboard(tf )
    AddViewToKeyboard(tf1 )
    AddViewToKeyboard(tf2 )
    AddViewToKeyboard(tf3 )

End Sub

See diff report below.
 

Attachments

  • beyondcompare_hidekeyboard_diff_report.pdf
    26.8 KB · Views: 354
Last edited:

moore_it

Well-Known Member
Licensed User
Longtime User
Hi all,
if i want to use this feature in an tableview textfields ?
I try but page.resignfocus not work and keyboard icon compare only at the last row.

Help is appreciate.
thanks
 
Last edited:
Top