Search code examples
androidsearchview

SearchView like in Google Maps Application


I'm going to tell how to is mysearch view.When Application starts keyboard must not show up, and search view is always expanded mode.

i am using this layout for search view btw it isn't menu item

 <FrameLayout
    android:layout_width="match_parent"
    android:layout_height="48dp"
    android:background="?attr/colorPrimary">

    <android.support.v7.widget.SearchView
        android:layout_marginLeft="52dp"
        android:layout_marginRight="8dp"
        android:id="@+id/searchview"
        android:background="@color/Transparent"
        android:layout_gravity="center_vertical"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</FrameLayout>


Arama = (SearchView) findViewById(R.id.searchview);
    Arama.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if(!hasFocus) {
                Arama.onActionViewCollapsed();
                Arama.setQuery("", false);
            }
        }
    });
    Arama.onActionViewExpanded();
    Arama.setQueryHint("Article");

<activity
        ....
        android:windowSoftInputMode="stateVisible">
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="...." />
    </activity>

when i do this,when application starts, my keyboard automatically shows up but i don't want it.When click, it will show up

How can i do that? Thanks for now.


Solution

  • Use this tag in your activity's manifest declaration if you wish not to show your keyboard when activity starts, but want to show when user clicks inside any EditText-

    <activity
        android:windowSoftInputMode="stateHidden" ... >
        ...
    </activity>
    

    Use android:windowSoftInputMode="stateAlwaysHidden" to never show your keyboard.

    Not in application tag, in Activity tag.

    Check other softInputMode tags here