How to create a Edittext in action bar in android?

假如想象 提交于 2019-12-07 01:08:00

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!