Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9191565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:42:53+00:00 2026-06-17T20:42:53+00:00

I have a application, and need to close the softkeyboard on a rather large

  • 0

I have a application, and need to close the softkeyboard on a rather large amount of actions. For example, when clicking a button, when a new layout is drawn, on screen orientation change, when the controller tells the UI to, et cetera.
I use the optionsMenuButton to flip view with a ViewFlipper, and obviously I want the keyboard to hide in the flipped view (there is no input field there).

I’ve tried these so far and tell why these aren’t reliable:

This one didn’t work because I have lots of editTexts, and other views. I need a more generic one, one that does not require a view as argument, if possible.

InputMethodManager imm = (InputMethodManager)getSystemService(
  Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);

This one does not work at all for me:

getWindow().setSoftInputMode(
  WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

This one works, but immediately pops the keyboard up again when the view is flipped.

InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);

This one works sometimes, but getCurrentFocus() returns null most of the time.

InputMethodManager inputManager = (InputMethodManager)            
Context.getSystemService(Context.INPUT_METHOD_SERVICE); 
inputManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(),      
InputMethodManager.HIDE_NOT_ALWAYS);

This one works only if the keyboard is shown:

getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);

This one does not work with the EditText like the first piece of code, but with the root Layout, which changes on orientation change and everytime the oncreate is called. I have different layout XML for landscape/portrait and normal/large. All the root Layouts have the ID root. This works nicely the first time, but after that, it doesn’t work anymore.

InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(findViewById(R.id.root).getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);

Bottomline: I’ve tried hella lot of softkeyboard hiding methods, but none of them seems to work reliably. Is there any method for hiding the soft keyboard reliably?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:42:54+00:00Added an answer on June 17, 2026 at 8:42 pm

    Since you need an EditText to bring up the keyboard, find the particular one and use the first method you displayed to hide the keyboard:

    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
    

    However, you will need that EditText. First, get all views:

    public static ArrayList<View> getAllViewsFromRoots(View...roots) {
        ArrayList<View> result = new ArrayList<View>();
        for (View root : roots) {
            getAllViews(result, root);
        }
        return result;
    }
    
    private static void getAllViews(ArrayList<View> allviews, View parent) {
        allviews.add(parent);
        if (parent instanceof ViewGroup) {
            ViewGroup viewGroup = (ViewGroup)parent;
            for (int i = 0; i < viewGroup.getChildCount(); i++) {
                getAllViews(allviews, viewGroup.getChildAt(i));
            }
        }
    }
    

    Then, get an EditText which is visible.

    public static EditText getEditText(View root) {
        ArrayList<View> views = getAllViewsFromRoots(root);
        for (View view : views) {
            if (view instanceof EditText && view.getVisibility() == View.VISIBLE) {
                return (EditText) view;
            }
        }
        return null;
    }
    

    Call somewhere:

    Toolkit.getEditText(((ViewParent) findViewById(android.R.id.content)).getChildAt(0));
    

    with that, call the hiding method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application window that displays a button. On button click, a new
I have an application window that displays a button. On button click, a new
I have a login form which I need to close without the entire application
I have a condition in which I need to close the application and so
I have two application that need to talk to each other. App1 needs to
I have an application I need to analyze. I have the source code here.
I have this application that need to do some things in protected paths (like
I have an application where I need to fire a notification on certain days
I have an application where I need to INSERT an auto_increment value from a
Hokay so I have an application where I need some IPC... I'm thinking named

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.