I would rather define your SearchView in the layout and then call
View v = findViewById(R.id.your_search_view); getSupportActionBar().setCustomView(v);
Thus, it is already aligned to the left, and if not, you can set its LayoutParams .
If you use the Toolbar with AppCompat, everything is simpler because it acts like a ViewGroup .
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:abc="http://schemas.android.com/apk/res-auto" android:id="@+id/toolbar" android:layout_height="?attr/actionBarSize" android:layout_width="match_parent"> <your.SearchView /> // here you have control over layout_gravity </android.support.v7.widget.Toolbar>
source share