MainActivity.java
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.widget.SearchView;
import android.widget.SearchView.OnQueryTextListener;
public class MainActivity extends ActionBarActivity {
private SearchView mSearchView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mSearchView = (SearchView) findViewById(R.id.search);
mSearchView.setIconifiedByDefault(true);
mSearchView.setFocusable(false);
mSearchView.clearFocus();
mSearchView.setOnQueryTextListener(new OnQueryTextListener() {
@Override
public boolean onQueryTextChange(String queryText) {
System.out.println("onQueryTextChange:" + queryText);
return true;
}
@Override
public boolean onQueryTextSubmit(String queryText) {
System.out.println("onQueryTextSubmit:" + queryText);
return true;
}
});
}
}
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<SearchView
android:id="@+id/search"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>