u_kami
u_kami

Reputation: 575

Android toolbar SearchView is automatically opening keyboard

I am having a weird problem. In my MainActivity toolbar I have an action search and this is how I use it:

@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        MenuItem searchItem = menu.findItem(R.id.search);
        SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
        searchView.setOnQueryTextListener(this);

        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        searchView.setSearchableInfo(searchManager.getSearchableInfo(
                new ComponentName(this, SearchableActivity.class)));
        searchView.setIconified(false);

        return true;
    }

but the problem here is that when my app starts the keyboard pops up before I even click the search button in the toolbar. I tried to force the keyboard to hide in the manifest I added this to my MainActivity:

android:windowSoftInputMode="stateAlwaysHidden"

I even tried this:

android:windowSoftInputMode="stateHidden"

but they keyboard still pops up. I don't have any EditText or anything I only have an image and a FAB in my MainActivity.

Upvotes: 2

Views: 3419

Answers (1)

Amit Patel
Amit Patel

Reputation: 1825

1) android:windowSoftInputMode="adjustPan|stateHidden"

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

3) mSearchView.clearFocus();

Upvotes: 8

Related Questions