How can I add a toolbar above the keyboard?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
Adding a toolbar above the keyboard is a common way to surface actions such as Done, Next, formatting, or quick-insert shortcuts while the user is typing. The implementation depends heavily on platform: iOS has first-class keyboard accessory APIs, while Android usually handles the same idea by laying UI above the IME or attaching controls to the input area.
On iOS UIKit, use inputAccessoryView
In UIKit, the standard solution is inputAccessoryView on UITextField or UITextView. A UIToolbar works especially well because it already knows how to host bar button items.
Whenever the text field becomes first responder, the toolbar appears above the keyboard automatically.
In SwiftUI, use keyboard toolbar placement
Modern SwiftUI has a cleaner API for this pattern:
This is usually preferable in SwiftUI because it integrates with the framework's focus system instead of forcing a UIKit accessory view bridge.
On Android, place controls with IME-aware layout
Android does not have an exact inputAccessoryView equivalent across the whole UI toolkit, but the common goal is the same: keep controls visible just above the soft keyboard.
In Jetpack Compose, an effective pattern is to place a row of actions at the bottom and let it move with the IME using imePadding():
This does not literally attach a view to the keyboard the way iOS does, but it achieves the same user experience by staying immediately above the IME.
Pick toolbar actions that match typing flow
A keyboard toolbar is most useful when it shortens the input task. Good examples include:
- dismiss keyboard
- move to next or previous field
- insert formatting markers
- add attachment, emoji, or mention actions
Bad toolbars try to cram unrelated navigation or destructive actions into a typing surface. Keep it focused on what the user needs while editing.
Common Pitfalls
The biggest mistake on iOS is creating the toolbar correctly but forgetting to assign it to inputAccessoryView or forgetting that only the current first responder shows it.
Another common issue is hard-coding toolbar size or frame values unnecessarily. UIToolbar.sizeToFit() usually handles this for you.
On SwiftUI, people sometimes fight the keyboard manually even though .toolbar(placement: .keyboard) already exists.
On Android, the common problem is treating the keyboard as a fixed-height object. Use IME-aware layout behavior instead of guessing its size.
Summary
- On iOS UIKit, use
inputAccessoryViewwith aUIToolbar. - On SwiftUI, prefer
.toolbarwithplacement: .keyboard. - On Android, keep controls above the IME with keyboard-aware layout, often via
imePadding(). - Limit the toolbar to actions that genuinely help text entry.
- Avoid manual keyboard sizing tricks when the platform already provides a layout-aware API.
Related reading
- How can I add CGPoint objects to an NSArray the easy way?
- How can I "add existing frameworks" in Xcode 4?
- How can I add files to the iOS simulator?
- How can I add Margin in Jetpack Compose?
- How can I add NSAppTransportSecurity to my info.plist file?
- How can I add the new Floating Action Button between two widgets/layouts
- How can I assign an ID to a view programmatically?
- How can I avoid concurrency problems when using SQLite on Android?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.