1

I am testing Dark Mode in iPhone 12 Pro (iOS 14.4). I enabled Dark Mode in Settings but my Keyboard remains the same. It does not appear in DarkMode.

I have 2 questions:

  1. Do we need to write code to change the appearance of the Keyboard or OS assigns the appearance to Keyboard from Settings. (Android does this way).

  2. If developer needs to handle the DarkMode appearance for keyboard then how can we do that?

I tried this code to change the color of the Keyboard in AppDelegate but it did not work.

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
     [ConfigManager setup];
     self.viewController = [[MainViewController alloc] init];
     BOOL result = [super application:application didFinishLaunchingWithOptions:launchOptions];

     // This is the code for changing the appearance of the keyboard
     [UITextField appearance].keyboardAppearance = UIKeyboardAppearanceDark;

     return result;
}

It's a Cordova based project and I am using CDVIonicKeyBoard Plugin.

pkamb
  • 33,281
  • 23
  • 160
  • 191
Rohit Singh
  • 16,950
  • 7
  • 90
  • 88

2 Answers2

1

In your code you are setting the standard system keyboard appearance to dark mode.

But if you are using Cordova based project and using CDVIonicKeyBoard Plugin, then you have to set the CDVIonicKeyBoard style to dark mode.

As I see from gitHub https://github.com/ionic-team/cordova-plugin-ionic-keyboard

They have provided information on how to set the Keyboard style programmatically to either dark or light mode.

// Possible values for 'KeyboardStyle'
Keyboard.setKeyboardStyle('light'); // <- default
Keyboard.setKeyboardStyle('dark');`

By default they set the keyboard style to light mode. To see the CDVIonicKeyBoard also in dark mode set the keyboard style to dark mode.

Nandish
  • 1,136
  • 9
  • 16
  • This sets the theme of keyboard on JavaScript side. How do I handle this from native (iOS) side? (For eg AppDelegate etc). – Rohit Singh Apr 20 '22 at 12:52
  • They mentioned it for `Keyboard.setKeyboardStyle (for iOS only)`.`Programmatically set the keyboard style ` They mentioned this for iOS only. Can you show me your code how you are using this CDVIonicKeyBoard plugin? – Nandish Apr 20 '22 at 13:26
  • Yes Keyboard.setKeyboardStyle does not work in Android. But this API is meant for Javascript. – Rohit Singh Apr 20 '22 at 14:33
  • Your question was asked for iOS only right? So iOS has the way mentioned. I am not sure about Android. And what keyboard you are using in iOS native side? Standard keyboard or CDVIonicKeyBoard in your app ? – Nandish Apr 20 '22 at 16:45
  • @RohitSingh if you think this answers your question then please accept the answer. – Nandish Apr 20 '22 at 20:46
0
  1. No, if you’re using the default keyboard provided by the system.

  2. The method you used would work fine, but not if you’re using a third party framework’s keyboard.

Daria
  • 26
  • 4