Search code examples
androidandroid-actionbarsearchview

android action bar home button method


I would like to close search view in action bar like home button closes it. Currently I am using intents, what method does action bar home button click does?

This is my way to cancel search or collapse it. Is there any smoother way?

case R.id.action_cancel:{
                Intent intent = new Intent(this, MainActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);

Solution

  • I used fragments and separate layout for "footer", that has EditText and cancel button in it