iOS Question Input Accessory Views

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can use NativeObject to set the accessory view. In this example it is a button:
B4X:
Dim b As Button
b.Initialize("b", b.STYLE_SYSTEM)
b.Text = "Click me"
b.Width = 100
b.Height = 50
Dim no As NativeObject = TextField1
no.SetField("inputAccessoryView", b)
You can also add a Panel with more views.
 
Upvote 0

Darren69

Member
Licensed User
Longtime User
Hello Erel,

How do I use the above code? all I want to do is add one button above the keyboard! Silly question I know but just wait until I hit you up with the push notifications one ;)
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Complete example:
B4X:
Sub Process_Globals
   Public App As Application
   Public NavControl As NavigationController
   Private Page1 As Page
   Dim tf As TextField
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")
   Page1.RootPanel.AddView(tf, 0, 0, 200, 100)
   Dim b As Button
   b.Initialize("b", b.STYLE_SYSTEM)
   b.Text = "Hide keyboard"
   b.Width = 100
   b.Height = 50
   AddViewToKeyboard(tf, b)
End Sub

Sub b_Click
   Page1.ResignFocus
End Sub

Sub AddViewToKeyboard(TextField1 As TextField, View1 As View)
   Dim no As NativeObject = TextField1
   no.SetField("inputAccessoryView", View1)
End Sub
 
Upvote 0

Arf

Well-Known Member
Licensed User
Longtime User
I've added this to my code, all compiles fine but I can't see any change to the keyboard. My code is below:
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Private pg As Page
    Private sb As StringBuilder
    Private serNumber As Label
    Private Done As Button
    Private NumEntryBox As TextField
    Private serNumber2 As Label
    Private serNumber3 As Label
    Dim tf As TextField

End Sub

Public Sub Show
    sb.Initialize
   
    If pg.IsInitialized = False Then
        pg.Initialize("pg")
        pg.RootPanel.LoadLayout("sNumberAsk")
        pg.HideBackButton = True '<-- don't want to allow the user to return to the login screen
    End If   
   
    Main.NavControl.ShowPage(pg)
   
    Dim b As Button
    b.Initialize("b", b.STYLE_SYSTEM)
    b.Text = "DONE"
    b.Width = 100
    b.Height = 50
    tf.Initialize("tf")
    AddViewToKeyboard(tf, b)
  
    serNumber.Text = "Please enter your serial number in the box below:"
    serNumber.Visible = True
    NumEntryBox.Enabled = True
    NumEntryBox.Visible = True
    Done.Visible = True
End Sub

Sub b_Click
   NumEntryBox_EnterPressed
End Sub

Sub AddViewToKeyboard(TextField1 As TextField, View1 As View)
   Dim no As NativeObject = TextField1
   no.SetField("inputAccessoryView", View1)
End Sub
 
Upvote 0

Arf

Well-Known Member
Licensed User
Longtime User
I am getting the following in the Logs window though:
Can't find keyplane that supports type 4 for keyboard iPhone-Portrait-NumberPad; using 563160167_Portrait_iPhone-Simple-Pad_Default
 
Upvote 0

Arf

Well-Known Member
Licensed User
Longtime User
Ah I got it working, needed to use NumEntryBox as the TextField for AddViewToKeyboard, not tf.
 
Upvote 0
Top