Keyboard plugin question


I am building an app with Cordova and am using the com.ionic.keyboard plugin.

I noticed in the plugins source commented out code for styleDark() under the iOS codebase. I had been looking everywhere for a Cordova plugin to style the keyboard dark and this was the closest I could find. It’s currently listed as remove styleDark until we know it's app store safe in Github; but this is over a year ago and it would seem that other live apps are allowed a dark keyboard?

Anyways, I uncommented all the code and have called cordova.plugins.Keyboard.styleDark(true); once the device ready event fires in my app. This seems to sort of work; yet only sometimes when a field is selected then changed to another field does the dark keyboard correctly render.

Most of the time when a field is tapped this keyboard appears (dark keyboard buttons, but with light keyboard background?):

But then as you can see here, I am able to sometimes correctly see the dark keyboard when tapping between fields:

Any suggestions on how to have the keyboard display dark all the time?



Anyone have any suggestions on this?


Anyone have any suggestions on this?

Having the same issue. From further testing it appears that it’s not just switching inputs - if you focus an input (and it shows up incorrectly with white text and no dark bg) then quickly blur and refocus the input, the correct (dark bg) keyboard shows up. Almost seems like the initial keyboard rise is “too quick” and the keyboard shows before the style had time to take place. Once you switch, though, the style finally shows.

Did you ever find a fix? I’m going to keep poking around a bit.

Agreed. No one seems to care on here - cool.

I actually got it working perfectly for iOS8 after changing the code Objective-C plugin code extensively, but iOS9 unfortunately completely broke the changes and I abandoned work on it at that point.

Could you share your working iOS8 code (or just talk about what you did)? I’d be down to take a look at making it work for 9.

Sure. About time someone else looks into getting this functionality working haha :wink:

After uncommenting the code from Ionic (which should allow you to change the keyboard between light/dark at any time) and finding it didn’t work, I tried the following:

This was in the AppDelegate.h
@implementation UIWebBrowserView (KeyboardSwitch)
- (UIKeyboardAppearance) keyboardAppearance{
return UIKeyboardAppearanceDark;

If iOS wasn’t being retarded then that should just force it dark all the time; unfortunately the problem arises where sometimes the keyboard’s color varies and is not always “dark appearance” by Apple.

I then tried many vastly different variations; all of which failed in one way or another (with the aforementioned iOS bug) until adding this to the IonicKeyboard.m worked:
- (void)formKeyboardWillShow:(NSNotification*)notif
UIWindow *keyboardWindow = nil;
for (UIWindow *windows in [[UIApplication sharedApplication] windows]) {
if (![[windows class] isEqual:[UIWindow class]]) {
keyboardWindow = windows;
for (UIView* peripheralView in [self getKeyboardViews:keyboardWindow]) {
[[peripheralView layer] setBackgroundColor: [UIColor colorWithRed:0.2 ``green:0.2 blue:0.2 alpha:1].CGColor];

Applying both of the code above was then working perfectly in iOS8; but broken again in iOS9. I would say this is somewhat to be expected as it changes the background color of some of the keyboard layers directly. This was done with a pretty perfect match to the correct dark keyboard appearance; but realistically would likely fail Apple app store guidelines (if they spotted it).

When iOS9 was released I tried for several more hours to manipulate the new layer structure and apply the same fix; but everything I tried ended up failing for one reason or another.

Best of luck with it; but really Apple should just fix the bug tbh