How to create edittext in action bar in android?

Can I use edit text in the action bar? After reading a lot of resources on Google, I could not find how to create the edit text in the action bar. Can someone tell me how to do this?

+4
source share
2 answers

You can set Viewcustom Viewfor ActionBaras follows:

getActionBar().setCustomView(R.layout.custom_actionbar);

Then you can search Viewsfrom custom Viewin ActionBaras follows:

View actionBarView = getActionBar().getCustomView();
EditText editText = (EditText) acitonBarView.findViewById(R.id.editText);

Or you can simply install the instance Viewas a user Viewas follows:

EditText editText = new EditText(context);
getActionBar().setCustomView(editText);
+3
+1

All Articles