Nutrient

Home

SDK

Software Development Kits

Low-Code

IT Document Solutions

Workflow

Workflow Automation Platform

DWS API

Document Web Services

T
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Company

About

Team

Careers

Contact

Security

Partners

Legal

Resources

Blog

Events

Try for free

Contact Sales
Contact sales
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

products

Web

Web

Document Authoring

AI Assistant

Salesforce

Mobile

iOS

Android

visionOS

Flutter

React Native

MAUI

Server

Document Engine

Document Converter Services

.NET

Java

Node.js

AIDocument Processing

All products

solutions

USECASES

Viewing

Editing

OCR and Data Extraction

Signing

Forms

Scanning & Barcodes

Markup

Generation

Document Conversion

Redaction

Intelligent Doc. Processing

Collaboration

Authoring

Security

INdustries

Aviation

Construction

Education

Financial Services

Government

Healthcare

Legal

Life Sciences

All Solutions

Docs

Guides overview

Web

AIAssistant

Document Engine

iOS

Android

visionOS

Java

Node.js

.NET

Document Converter Services

Downloads

Demo

Support

Log in

Resources

Blog

Events

Pricing

Try for free

Free Trial

Company

About

Security

Partners

Legal

Contact Sales
Contact Sales
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

products

Products overview

Document Converter

Document Editor

Document Searchability

Document Automation Server

Integrations

SharePoint

Power Automate

Nintex

OneDrive

Teams

Window Servers

solutions

USECASES

Conversion

Editing

OCR Data Extraction

Tagging

Security Compliance

Workflow Automation

Solutions For

Overview

Legal

Public Sector

Finance

All Solutions

resources

Help center

Document Converter

Document Editor

Document Searchability

Document Automation Server

learn

Blog

Customer stories

Events

Support

Log in

Pricing

Try for free

Company

About

Security

Partners

Legal

Contact Sales
Contact Sales
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Product

Product overview

Process Builder

Form Designer

Document Viewer

Office Templating

Customization

Reporting

solutions

Industries

Healthcare

Financial

Manufacturing

Pharma

Education

Construction

Nonprofit

Local Government

Food and Beverage

Departments

ITServices

Finance

Compliance

Human Resources

Sales

Marketing

Services

Overview

Capex-accelerator

Process Consulting

Workflow Prototype

All Solutions

resources

Help center

guides

Admin guides

End user guides

Workflow templates

Form templates

Training

learn

Blog

Customer stories

Events

Support

Pricing

Support

Company

About

Security

Partners

Legal

Try for Free
Contact Sales
Try for Free
Contact Sales
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Services

Generation

Editing

Conversion

Watermarking

OCR

Table Extraction

Pricing

Docs

Log in

Try for Free
Try for Free

Free trial

Blog post

The Soft Keyboard on Android

Anastasiia Zhuravleva Anastasiia Zhuravleva

Table of contents

  • windowSoftInputMode in Android Manifest
  • How to Hide the Soft Keyboard
  • How to Show the Soft Keyboard
  • Conclusion
Illustration: The Soft Keyboard on Android

The soft keyboard (also called the onscreen keyboard) is the main input method on Android devices, and almost every Android developer needs to work with this component at some point. At first glance, it may seem like a trivial task, since the only operations you usually want are for showing and hiding the keyboard — actions that can happen automatically through the available Android APIs. But there’s a bit more to the soft keyboard than meets the eye, so let’s take a look at offered APIs and try to understand what are they used for.

windowSoftInputMode in Android Manifest

The windowSoftInputMode attribute is set on the activity — usually through the Android manifest — and it specifies the way the onscreen keyboard behaves when an activity comes into a user’s focus. We suggest first checking out the available customization options to see if they will be enough for a particular use case before writing any custom keyboard handling logic.

Using this attribute, it’s possible to influence two aspects:

  • The visibility of the soft keyboard when the activity receives the focus (stateUnspecified, stateHidden, stateAlwaysVisible, etc.).

  • The changes made to the activity’s main window to accommodate the keyboard view. The options here are resizing, which will make the activity layout small in order to free space for the keyboard, or panning the activity’s contents to make the current focus view visible and keep the part of the window under the soft keyboard (adjustUnspecified, adjustResize, and adjustPan).

Take a look at the official documentation for windowSoftInputMode for more information.

All that said, if windowSoftInputMode customization options aren’t sufficient for your use case, here is how to manually control the visibility of the soft keyboard.

How to Hide the Soft Keyboard

Because hiding the keyboard is more complex than showing it, and because it’s required more often, let’s start with it.

The required way for an application to hide the soft keyboard is by using InputMethodManager#hideSoftInputFromWindow. However, to access this functionality, it’s necessary to provide a context and a window token. Getting the context is usually trivial, but you may be wondering what the window token is and what it’s used for.

A window token is a special token used by the window manager to uniquely identify a window in the system. It is important for security reasons; it makes it impossible to draw on top of the windows of other applications, thereby preventing potential malicious intent.

So, even though our intention is to hide the keyboard, we still must provide a window token that matches the window currently accepting input. Otherwise, InputMethodManager will reject the request. This security mechanism prevents one application from force-closing the keyboard opened by another application.

Now that we know more about the window token, the next question is how we get it. Unfortunately, there is no one way to request the window token on all devices and APIs, but we’ll present a few that should work in most cases.

Here is how to hide the soft keyboard:

fun hideKeyboard(view: View) {
   // Retrieving the token if the view is hosted by the fragment.
   var windowToken: IBinder? = view.windowToken

   // Retrieving the token if the view is hosted by the activity.
   if (windowToken == null) {
       if (view.context is Activity) {
           val activity = view.context as Activity
           if (activity.window != null && activity.window.decorView != null) {
               windowToken = activity.window.decorView.windowToken
           }
       }
   }

   // Hide if shown before.
   val inputMethodManager = view
        .context
        .getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
   inputMethodManager.hideSoftInputFromWindow(windowToken, 0)
}
void hideKeyboard(final @NonNull View view) {
   // Retrieving the token if the view is hosted by the fragment.
   IBinder windowToken = view.getWindowToken();

   // Retrieving the token if the view is hosted by the activity.
   if (windowToken == null) {
       if (view.getContext() instanceof Activity) {
           final Activity activity = (Activity) view.getContext();
           if (activity.getWindow() != null && activity.getWindow().getDecorView() != null) {
               windowToken = activity.getWindow().getDecorView().getWindowToken();
           }
       }
   }

   // Hide if shown before.
   InputMethodManager inputMethodManager = (InputMethodManager) view
        .getContext()
        .getSystemService(Context.INPUT_METHOD_SERVICE);
   inputMethodManager.hideSoftInputFromWindow(windowToken, 0);
}

How to Show the Soft Keyboard

Let’s take a look at a simple API for showing the soft keyboard. To do this, there is no longer a need to provide a window token. However, there is a small tweak required in order to make sure that the keyboard is correctly shown in landscape mode:

fun showKeyboard(view: View) {
   // When we want the keyboard to be displayed on phones in landscape mode, we need
   // to specify the `SHOW_FORCED` flag to correctly show the fullscreen keyboard.
   val isLandscape = view
       .context
       .resources
       .configuration
       .orientation == Configuration.ORIENTATION_LANDSCAPE

   val flags = if (isLandscape) SHOW_FORCED else SHOW_IMPLICIT

   val inputMethodManager = view
       .context
       .getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
   inputMethodManager.showSoftInput(view, flags)
}
void showKeyboard(final @NonNull View view) {
   // When we want the keyboard to be displayed on phones in landscape mode, we need
   // to specify the `SHOW_FORCED` flag to correctly show the fullscreen keyboard.
   final boolean isLandscape = view
       .getContext()
       .getResources()
       .getConfiguration()
       .orientation == Configuration.ORIENTATION_LANDSCAPE;

   int flags = isLandscape ? SHOW_FORCED : SHOW_IMPLICIT;

   InputMethodManager inputMethodManager = (InputMethodManager) view
       .getContext()
       .getSystemService(Context.INPUT_METHOD_SERVICE);
   inputMethodManager.showSoftInput(view, flags);
}

In this code snippet, we used the SHOW_FORCED flag for landscape mode instead of the usual SHOW_IMPLICIT flag in order to make sure the keyboard will be correctly displayed. The documentation for the SHOW_IMPLICIT flag states that this request is indeed implicit and the system might not favor the request in some circumstances, with landscape mode appearing to be one of such cases.

Conclusion

In this blog post, we discussed what the soft keyboard is and the reason why it’s more complicated to hide than it is to show. Hopefully this has given you a better overview of the soft keyboard and some helpful tips for working with it.

Explore related topics

Android Tips Development
Free trial Ready to get started?
Free trial

Related articles

Explore more
SDKDEVELOPMENTTUTORIALSiOSAndroidWebHow ToPDF

Understanding fonts in PDFs: A comprehensive guide

SDKRELEASESNutrient AI AssistantNutrient iOS SDKNutrient Android SDKiOSAndroid

AI Assistant for iOS and Android: Intelligent document interaction, now in your users’ pockets

SDKDEVELOPMENTAndroidJetpack ComposeDevelopment

Drag-to-reorder with Jetpack Compose

Company
About
Security
Team
Careers
We're hiring
Partners
Legal
Products
SDK
Low-Code
Workflow
DWS API
resources
Blog
Events
Customer Stories
Tutorials
News
connect
Contact
LinkedIn
YouTube
Discord
X
Facebook
Popular
Java PDF Library
Tag Text
PDF SDK Viewer
Tag Text
React Native PDF SDK
Tag Text
PDF SDK
Tag Text
iOS PDF Viewer
Tag Text
PDF Viewer SDK/Library
Tag Text
PDF Generation
Tag Text
SDK
Web
Tag Text
Mobile/VR
Tag Text
Server
Tag Text
Use Cases
Tag Text
Industries
Tag Text
Resources
Blog
Tag Text
Events
Customer Stories
Tag Text
Tutorials
Tag Text
Features List
Tag Text
Compare
Tag Text
community
Free Trial
Tag Text
Documentation
Tag Text
Nutrient Portal
Tag Text
Contact Support
Tag Text
Company
About
Tag Text
Security
Tag Text
Careers
Tag Text
Legal
Tag Text
Pricing
Tag Text
Partners
Tag Text
connect
Contact
Tag Text
LinkedIn
Tag Text
YouTube
Tag Text
Discord
Tag Text
X
Tag Text
Facebook
Tag Text
low-code
Document Converter
Tag Text
Document Editor
Tag Text
Document Automation Server
Tag Text
Document Searchability
Tag Text
Use Cases
Tag Text
Industries
Tag Text
Resources
Blog
Tag Text
Events
Customer Stories
Tag Text
Support
Help Center
Tag Text
Contact Support
Tag Text
Log In
Tag Text
Company
About
Tag Text
Careers
Tag Text
Security
Tag Text
Legal
Tag Text
Pricing
Tag Text
Partners
Tag Text
connect
Contact
Tag Text
LinkedIn
Tag Text
YouTube
Tag Text
Discord
Tag Text
X
Tag Text
Facebook
Tag Text
Popular
Approvals matrix
Tag Text
BPMS
Tag Text
Budgeting process
Tag Text
CapEx approval
Tag Text
CapEx automation
Tag Text
Document approval
Tag Text
Task automation
Tag Text
workflow
Overview
Tag Text
Services
Tag Text
Industries
Tag Text
Departments
Tag Text
Resources
Blog
Tag Text
Events
Customer Stories
Tag Text
Support
Help Center
Tag Text
FAQ
Tag Text
Troubleshooting
Tag Text
Contact Support
Tag Text
Company
About
Tag Text
Careers
Tag Text
Security
Tag Text
Legal
Tag Text
Pricing
Tag Text
Partners
Tag Text
connect
Contact
Tag Text
LinkedIn
Tag Text
YouTube
Tag Text
Discord
Tag Text
X
Tag Text
Facebook
Tag Text
DWS api
PDF Generator
Tag Text
Editor
Tag Text
Converter API
Tag Text
Watermark
Tag Text
OCR
Tag Text
Table Extraction
Tag Text
Resources
Log in
Tag Text
Help Center
Tag Text
Support
Tag Text
Blog
Tag Text
Company
About
Tag Text
Careers
Tag Text
Security
Tag Text
Pricing
Tag Text
Legal
Privacy
Tag Text
Terms
Tag Text
connect
Contact
Tag Text
X
Tag Text
YouTube
Tag Text
Discord
Tag Text
LinkedIn
Tag Text
Facebook
Tag Text

Copyright 2025 Nutrient. All rights reserved.

Thank you for subscribing to our newsletter!

We’re thrilled to have you join our community. You’re now one step closer to receiving the latest updates, exclusive content, and special offers directly in your inbox.

This builtin is not currently supported: DOM

PSPDFKit is now Nutrient. We've consolidated our group of trusted companies into one unified brand: Nutrient. Learn more

This builtin is not currently supported: DOM

PSPDFKit is now Nutrient. We've consolidated our group of trusted companies into one unified brand: Nutrient. Learn more

This builtin is not currently supported: DOM

New Feature Release. Tap into revolutionary AI technology to instantly complete tasks, analyze text, and redact key information across your documents. Learn More or View Showcase

This builtin is not currently supported: DOM

Aquaforest and Muhimbi are now Nutrient. We've consolidated our group of trusted companies into one unified brand: Nutrient. Learn more

This builtin is not currently supported: DOM

Integrify is now Nutrient. We've consolidated our group of trusted companies into one unified brand: Nutrient. Learn more

This builtin is not currently supported: DOM

Join us on April 15th. Join industry leaders, product experts, and fellow professionals at our exclusive user conference. Register for conference