How to change the color of the navigation bar from an input method service?

Viewed 383

I am working on a custom keyboard, so I implemented a class that implements an InputMethodService. There are already many posts about changing the color of the navigation bar in a regular activity - this is done by calling getWindow().setNavigationBarColor(), but I want to do the same for my keyboard: adjust the color of the navigation bar to the background color of my keyboard!

In an InputMethodService, I can access a window by getWindow(), but it is a instance of the SoftInputWindow class, so it does not offer a setNavigationBarColor method. Does anybody know how to achieve this?

There is a beta version of Gboard that can adjust the color of the navigation bar, so it seems to be possible...

1 Answers

Try using getWindow().getWindow() inside the InputMethodService instead of just the single getWindow() call.

It seems that the first getWindow() call returns a SoftInputWindow which is a type of Dialog, but you can call getWindow() again on it to get a PhoneWindow that is a proper Window, and that has the function you're looking for.

If you need a full example to look at, here's a code sample from Google's own codebase. I ran into this problem recently myself and this example is how I figured out how to do it.

Related