问题
Can we use an edit text in action bar? After reading lot of resources in Google i could not find how to create an edit text in action bar. Can anyone tell me how do i do it?
回答1:
You can set a custom View for the ActionBar like this:
getActionBar().setCustomView(R.layout.custom_actionbar);
You can then find Views from the custom View in the ActionBar like this:
View actionBarView = getActionBar().getCustomView();
EditText editText = (EditText) acitonBarView.findViewById(R.id.editText);
Or you can just directly set a View instance as custom View like this:
EditText editText = new EditText(context);
getActionBar().setCustomView(editText);
回答2:
Try this::
First url Second url
来源:https://stackoverflow.com/questions/24968338/how-to-create-a-edittext-in-action-bar-in-android