Android examples for Activity:Activity Fragment
This is how you get it if you are using Support Lib v4 (aka FragmentActivity)
import android.annotation.TargetApi; import android.content.Context; import android.support.v4.view.MenuItemCompat; import android.support.v7.widget.SearchView; import android.view.MenuItem; import android.widget.AutoCompleteTextView; import android.widget.EditText; import android.widget.TextView; public class Main{ /**/* w w w . jav a 2 s.com*/ * This is how you get it if you are using Support Lib v4 (aka FragmentActivity) */ @TargetApi(11) public static EditText GetActionBarSeachEditText(MenuItem item, int SearchViewId) { AutoCompleteTextView editText; android.widget.SearchView sv = (android.widget.SearchView) item .getActionView().findViewById(SearchViewId); int id = sv.getContext().getResources() .getIdentifier("android:id/search_src_text", null, null); editText = (AutoCompleteTextView) sv.findViewById(id); return editText; } }