How can i add search view to action bar in single activity with back arrow button not for all activity's?

282
July 17, 2017, at 10:20 PM

i am navigating to members list Activity from drawer menu, here i need search view and back arrow button. when user clicks on search icon i want to expand it after completion of work he will navigate to back using arrow button. how to achieve this.

Answer 1

try this

1. create a search_layout like this

<?xml version="1.0" encoding="utf-8"?>
<EditText xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/searchfield"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:background="@drawable/custom_search_edit"
 android:hint="@string/search_hint"
 android:inputType="textFilter"
 android:textColor="@color/colorBlack"
 android:textColorHint="@color/colorAccent"
 android:textSize="15sp" />

2. add this code in your activity

 getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setCustomView(R.layout.search_layout);
     EditText search = (EditText) getSupportActionBar().getCustomView().
            findViewById(R.id.searchfield);
    search.setOnEditorActionListener(new EditText.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId,
                                      KeyEvent event) {
            return true;
        }
    });
    getSupportActionBar().setDisplayOptions(getSupportActionBar().DISPLAY_SHOW_CUSTOM
            | getSupportActionBar().DISPLAY_SHOW_HOME);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

or you can use Searchview

Rent Charter Buses Company
READ ALSO
Android - Printing Euro currency character in Bixolon mobile printer

Android - Printing Euro currency character in Bixolon mobile printer

I'm trying to print the Euro currency character in a Bixolon SPP-R200III'm using the last sdk for android from Bixolon web

282
How to publish versioned binaries in Artifactory knowing their paths in the repository?

How to publish versioned binaries in Artifactory knowing their paths in the repository?

I think I am missing something here, I'll explain what I need to doWe are planning the move to Git, we currently use something else

204
Node js Keeps redirecting - Middleware

Node js Keeps redirecting - Middleware

I am trying to write a middleware using node js and expressIf user is not authenticated it will redirect him to login page

301
Angular JS reinitialize service

Angular JS reinitialize service

I have an angular js service which returns a node js WebSocket connection

388