I want to be able to show the free-dot menu always without using ActionBar. Just 3 dots menu + items in it, that's it.
How can I do that? Here's my code
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MyMainActivity">
<item
android:id="#+id/empty"
android:showAsAction="always"
android:title="#string/dot_menu"
android:icon="#android:drawable/ic_menu_more">
<menu>
<item
android:id="#+id/item1"
android:showAsAction="ifRoom"
android:title="#string/item1" />
<item
android:id="#+id/item2"
android:showAsAction="ifRoom"
android:title="#string/item2" />
<!-- ........... -->
And:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
//.....
}
It doesn't show a menu at all.
Try this code, I hope it's helpful.
<?xml version="1.0" encoding="utf-8"?>
<item
android:id="#+id/item_admin"
android:showAsAction="ifRoom|withText"
android:title="#string/item_admin"
android:visible="false"
tools:ignore="AppCompatResource" />
<item
android:id="#+id/item_masterpass_preferences"
android:showAsAction="ifRoom|withText"
android:title="#string/text_1"
android:visible="true"
tools:ignore="AppCompatResource" />
<item
android:id="#+id/item_shipping_addresses"
android:showAsAction="ifRoom|withText"
android:title="#string/text_2"
android:visible="true"
tools:ignore="AppCompatResource" />
<item
android:id="#+id/item_switch_language"
android:showAsAction="ifRoom|withText"
android:title="#string/text_3"
android:visible="false"
tools:ignore="AppCompatResource" />
<item
android:id="#+id/item_support_contact"
android:showAsAction="ifRoom|withText"
android:title="#string/text_4"
android:visible="true"
tools:ignore="AppCompatResource" />
Related
I have a Main Activity that controls 3 Fragments. The MainActivity has a searchbar and some filters on the options menu. The problem is that one of the fragments (ResultadosFragment) has its own implementation of OnCreateOptionsMenu(), where it inflates its own menu. What happens is that the options of both - the MainActivity and the Fragment - menus get mixed together in only one option menu.
Here's a screenshot:
MainActivity - OnCreateOptionsMenu()
#Override
public boolean onCreateOptionsMenu(final Menu menu) {
super.onCreateOptionsMenu(menu);
mOptionsMenu = menu;
//Carrega o arquivo de menu.
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_search_bar, menu);
menu.findItem(R.id.usado).setChecked(true);
menu.findItem(R.id.longplay).setChecked(true);
menu.findItem(R.id.nacional).setChecked(true);
//Pega o Componente.
final SearchView mSearchView = (SearchView) menu.findItem(R.id.search)
.getActionView();
//Define um texto de ajuda:
mSearchView.setQueryHint("Banda - Álbum");
// exemplos de utilização:
mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
#Override
public boolean onQueryTextSubmit(String query) {
searchQueryGlobal = query;
realizarPesquisa();
mSearchView.setIconified(true);
mSearchView.clearFocus();
// call your request, do some stuff..
// collapse the action view
if (menu != null) {
(menu.findItem(R.id.search)).collapseActionView();
}
return false;
}
#Override
public boolean onQueryTextChange(String newText) {
Log.i("well", " this worked");
return false;
}
});
return true;
}
menu_search_bar.XML
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.marcelofb.cratediggersguide.MainActivity">
<item
android:id="#+id/search"
android:icon="#android:drawable/ic_menu_search"
android:title="#string/search_title"
app:actionViewClass="android.support.v7.widget.SearchView"
app:showAsAction="collapseActionView|ifRoom"/>
<!-- <item
android:id="#+id/searchOptions"
android:title="Tools"
android:icon="#android:drawable/ic_menu_manage"
app:showAsAction="always" /> -->
<item android:title="Menu No. 2">
<group android:id="#+id/radioGroupNovoUsado" android:checkableBehavior="single">
<item
android:id="#+id/novo"
android:title="NOVO"
app:showAsAction="never" >
</item>
<item
android:id="#+id/usado"
android:title="USADO"
app:showAsAction="never" />
</group>
</item>
<item android:id="#+id/radioGroupCompactoLPItem"
android:title="Menu No. 2">
<group android:id="#+id/radioGroupCompactoLP" android:checkableBehavior="single">
<item
android:id="#+id/compacto"
android:title="COMPACTO"
app:showAsAction="never" />
<item
android:id="#+id/longplay"
android:title="LP"
app:showAsAction="never" />
</group>
</item>
<item android:id="#+id/radioGroupNacionalImportadoItem"
android:title="Menu No. 2">
<group android:id="#+id/radioGroupNacionalImportado" android:checkableBehavior="single">
<item
android:id="#+id/nacional"
android:title="NACIONAL"
app:showAsAction="never" />
<item
android:id="#+id/importado"
android:title="IMPORTADO"
app:showAsAction="never" />
</group>
</item>
ResultadosFragment - OnCrateOptionsMenu() AND onOptionsItemSelected()
#Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
// Inflate the menu; this adds items to the action bar if it is present.
inflater.inflate(R.menu.menu_resultados, menu);
super.onCreateOptionsMenu(menu, inflater);
mOptionsMenu = menu;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.menuRemoveLowReputation:
exibirMensagemReputacaoMaxima();
return true;
/**case R.id.menuSortClosest:
exibirMensagemEdt();
return true;**/
case R.id.menuSortClosestGps:
trimmarAteCoeficienteQuinze();
return true;
case R.id.menuDeleteMaiorQue:
exibirMensagemDeletarMaiorQue();
return true;
case R.id.menuInserirCep:
exibirMensagemInserirCep();
return true;
case R.id.menuSortPrecoMenorNormalPacTabelado:
sortCheaperNormalPacTabelado();
mAdapter.clear();
mAdapter.addAll(recordsGlobal);
mAdapter.notifyDataSetChanged();
mAdapter.notifyDataSetInvalidated();
return true;
case R.id.menuSortPrecoMenorExpressoSedex:
sortCheaperExpressoSedexTabelado();
mAdapter.clear();
mAdapter.addAll(recordsGlobal);
mAdapter.notifyDataSetChanged();
mAdapter.notifyDataSetInvalidated();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
menu_resultados.XML
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
app:showAsAction="ifRoom"
tools:context="com.example.marcelofb.cratediggersguide.MainActivity">
<item
android:id="#+id/menuRemoveLowReputation"
android:title="Remover reputação baixa" />
<!-- <item
android:id="#+id/menuSortClosest"
android:title="Mais Próximos - CEP" /> -->
<item
android:id="#+id/menuSortClosestGps"
android:title="C.V menor 15" />
<item
android:id="#+id/menuDeleteMaiorQue"
android:title="Deletar maior que" />
<item
android:id="#+id/menuInserirCep"
android:title="Inserir novo CEP para Frete" />
<item
android:id="#+id/menuSortPrecoMenorNormalPacTabelado"
android:title="Listar por preço menor Normal/Pac/Tabelado" />
<item
android:id="#+id/menuSortPrecoMenorExpressoSedex"
android:title="Listar por preço menor Expresso/Sedex" />
You can write menu.clear() in OnCreateOptionsMenu()
#Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.clear();
inflater.inflate(R.menu.menu, menu);
}
I do not know if it's the best practice. If someone knows tell us. =)
These changes solved the issue!
menu_search_bar.XML
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.marcelofb.cratediggersguide.MainActivity">
<item
android:id="#+id/search"
android:icon="#android:drawable/ic_menu_search"
android:title="#string/search_title"
app:actionViewClass="android.support.v7.widget.SearchView"
app:showAsAction="collapseActionView|always" />
<item
android:id="#+id/searchOptions"
android:icon="#android:drawable/ic_menu_manage"
android:title="Tools"
app:showAsAction="always">
<menu>
<item android:title="Menu No. 2">
<group
android:id="#+id/radioGroupNovoUsado"
android:checkableBehavior="single">
<item
android:id="#+id/novo"
android:title="NOVO"
app:showAsAction="never"></item>
<item
android:id="#+id/usado"
android:title="USADO"
app:showAsAction="never" />
</group>
</item>
<item
android:id="#+id/radioGroupCompactoLPItem"
android:title="Menu No. 2">
<group
android:id="#+id/radioGroupCompactoLP"
android:checkableBehavior="single">
<item
android:id="#+id/compacto"
android:title="COMPACTO"
app:showAsAction="never" />
<item
android:id="#+id/longplay"
android:title="LP"
app:showAsAction="never" />
</group>
</item>
<item
android:id="#+id/radioGroupNacionalImportadoItem"
android:title="Menu No. 2">
<group
android:id="#+id/radioGroupNacionalImportado"
android:checkableBehavior="single">
<item
android:id="#+id/nacional"
android:title="NACIONAL"
app:showAsAction="never" />
<item
android:id="#+id/importado"
android:title="IMPORTADO"
app:showAsAction="never" />
</group>
</item>
</menu>
</item>
menu_resultados.XML
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
app:showAsAction="ifRoom"
tools:context="com.example.marcelofb.cratediggersguide.MainActivity">
<item
android:id="#+id/searchOptions"
android:icon="#drawable/ic_filter_list_white_24dp"
android:title="Tools"
app:showAsAction="always">
<menu>
<item
android:id="#+id/menuRemoveLowReputation"
android:title="Remover reputação baixa" />
<!-- <item
android:id="#+id/menuSortClosest"
android:title="Mais Próximos - CEP" /> -->
<item
android:id="#+id/menuSortClosestGps"
android:title="C.V menor 15" />
<item
android:id="#+id/menuDeleteMaiorQue"
android:title="Deletar maior que" />
<item
android:id="#+id/menuInserirCep"
android:title="Inserir novo CEP para Frete" />
<item
android:id="#+id/menuSortPrecoMenorNormalPacTabelado"
android:title="Listar por preço menor Normal/Pac/Tabelado" />
<item
android:id="#+id/menuSortPrecoMenorExpressoSedex"
android:title="Listar por preço menor Expresso/Sedex" />
</menu>
</item>
here's my problem:
I have that nice toolbar with the icons in landscape mode:
after expanding the search view and showing the popup menu the "add" item appears (I thought that it shouldn't):
then returning with the back arrow key, as you see, the add button goes:
and you won't find it in the popup menu anymore:
I'm using support:appcompat-v7:25.1.0, and here's my menu code:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/app_bar_search"
android:actionViewClass="android.support.v7.widget.SearchView"
android:icon="#drawable/ic_action_search"
android:title="Search"
app:showAsAction="always|collapseActionView"
android:enabled="true"
android:visible="true"
app:actionViewClass="android.support.v7.widget.SearchView"/>
<item android:title="Add"
android:enabled="true"
android:icon="#drawable/ic_action_add"
android:visible="true"
app:showAsAction="ifRoom"
android:id="#+id/add" />
<item android:title="Settings"
android:id="#+id/settings"
app:showAsAction="never"
android:icon="#drawable/ic_action_settings"
android:enabled="true"
android:visible="true" />
<item android:title="Feedback"
android:id="#+id/feedbvack"
app:showAsAction="never"
android:icon="#drawable/ic_action_feedback"
android:enabled="true"
android:visible="true" />
</menu>
I can set the add button showAsAction to "always" but I know that this is discouraged.
Does anyone here know why is there this behavior? and how can I prevent that?
Thanks in advance.
You can try to use this:
MenuItemCompat.setOnActionExpandListener(searchMenuItem, new MenuItemCompat.OnActionExpandListener() {
#Override
public boolean onMenuItemActionExpand(MenuItem item) {
return true;
}
#Override
public boolean onMenuItemActionCollapse(MenuItem item) {
supportInvalidateOptionsMenu();
//or use invalidateOptionsMenu();
return true;
}
});
So when SearchView will be collapsed Toolbar will reallocate items and ifRoom items will be visible. I had this bug too and solved it this way.
Try this
<item
android:id="#+id/app_bar_search"
android:actionViewClass="android.support.v7.widget.SearchView"
android:icon="#drawable/ic_action_search"
android:title="Search"
app:showAsAction="always|collapseActionView"
android:enabled="true"
android:visible="true"
app:actionViewClass="android.support.v7.widget.SearchView"/>
<item android:title="Add"
android:enabled="true"
android:icon="#drawable/ic_action_add"
android:visible="true"
app:showAsAction="always"
android:id="#+id/add" />
<item android:title="Settings"
android:id="#+id/settings"
app:showAsAction="never"
android:icon="#drawable/ic_action_settings"
android:enabled="true"
android:visible="true" />
<item android:title="Feedback"
android:id="#+id/feedbvack"
app:showAsAction="never"
android:icon="#drawable/ic_action_feedback"
android:enabled="true"
android:visible="true" />
Set app:showAsAction to always to make sure it will be visible always.
Use of ifRoom has this feature if space available it will show or else it will hide it better use always or never
<item android:title="Add"
android:enabled="true"
android:icon="#drawable/ic_action_add"
android:visible="true"
app:showAsAction="always"
android:id="#+id/add" />
#Kovy has answered above with the fix for this bug and I confirm it fixes the bug. Thank you very much, mate! However, the above function has been deprecated in favour of individual menu items OnActionExpandListener. Example of it is as posted below:
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.menu, menu);
MenuItem searchItem = menu.findItem(R.id.action_search);
searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
#Override
public boolean onMenuItemActionExpand(MenuItem item) {
return true;
}
#Override
public boolean onMenuItemActionCollapse(MenuItem item) {
supportInvalidateOptionsMenu();
return true;
}
});
I'm trying to declare the slider items as a Button but it keeps on crashing. I'm trying to access a different Activity when an item is pressed, and trying out the Log out button. Here's the xml of the activity_main_drawer.
<group android:checkableBehavior="single">
<item
android:id="#+id/home"
android:icon="#drawable/menu_home"
android:title="Home"
/>
<item
android:id="#+id/nav_medication"
android:icon="#drawable/menu_medication"
android:title="Medication" />
<item
android:id="#+id/notices"
android:icon="#drawable/menu_notices"
android:title="Doctor's Notices" />
<item
android:id="#+id/meds"
android:icon="#drawable/menu_buy"
android:title="Buy Medicines" />
<item
android:id="#+id/options"
android:icon="#drawable/ic_menu_manage"
android:title="Medic Options">
<menu>
<group android:checkableBehavior="single">
<item
android:id="#+id/nav_add"
android:icon="#drawable/menu_add"
android:title="Add Medicines" />
<item
android:id="#+id/nav_dispense"
android:icon="#drawable/menu_dispense"
android:title="Dispense" />
</group>
</menu>
</item>
</group>
<item android:title="Settings">
<menu>
<item
android:id="#+id/account"
android:icon="#drawable/menu_account"
android:title="Account" />
<item
android:id="#+id/help"
android:icon="#drawable/menu_help"
android:title="Help" />
<item
android:id="#+id/bLogout"
android:icon="#drawable/menu_help"
android:title="Logout"
/>
</menu>
</item>
Tried using:
Button bLogout;
bLogout = (Button) findViewById(R.id.bLogout);
bLogout.setOnClickListener(this);
But it still crashes.
Use this NavigationView item clicked
navView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
#Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
switch (menuItem.getItemId()) {
case R.id. bLogout:
// your logic goes here
break;
}
}
});
I want to show icon in Option Menus. I tried many methods but I can't find success.In my toolbar some icon already put but i want icon in my Option menu.
I want same as below image:-
My menu.xml:-
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">
<item
android:id="#+id/action_search"
android:title="#string/action_search"
android:orderInCategory="1"
android:icon="#drawable/search"
app:showAsAction="ifRoom" />
<item
android:id="#+id/action_cart"
android:title="#string/action_search"
android:orderInCategory="2"
android:icon="#drawable/shoppingcart"
android:actionLayout="#layout/feed_update_count"
app:showAsAction="ifRoom" />
<item
android:id="#+id/menu_overflow"
android:title="#string/my_cart"
android:icon="#drawable/ic"
android:orderInCategory="11111"
app:showAsAction="always">
<menu>
<item
android:id="#+id/login"
android:title="#string/login"
android:orderInCategory="1"
android:icon="#drawable/account"
app:showAsAction="always|withText"/>
<item
android:id="#+id/my_order"
android:title="#string/my_order"
android:orderInCategory="2"
android:icon="#drawable/track"
app:showAsAction="withText"/>
<item
android:id="#+id/wishlist"
android:title="#string/wishlist"
android:orderInCategory="3"
android:icon="#drawable/wishlist"
app:showAsAction="withText"/>
</menu>
</item>
</menu>
I am new in android developing anyone can help me how to show icon in option menu. Thanks in advance!
By default the overflow menu will disable the icon and only show text, you need some workaround.
1st way
You can enable it by adding the following codes into your class
#Override
public boolean onMenuOpened(int featureId, Menu menu)
{
if(featureId == Window.FEATURE_ACTION_BAR && menu != null){
if(menu.getClass().getSimpleName().equals("MenuBuilder")){
try{
Method m = menu.getClass().getDeclaredMethod(
"setOptionalIconsVisible", Boolean.TYPE);
m.setAccessible(true);
m.invoke(menu, true);
}
catch(NoSuchMethodException e){
Log.e(TAG, "onMenuOpened", e);
}
catch(Exception e){
throw new RuntimeException(e);
}
}
}
return super.onMenuOpened(featureId, menu);
}
2nd way
Create your own overflow item and a nested menu to show both the icon and the text.
Example,
<item
android:id="#+id/overflow"
android:icon="#drawable/ic_overflow_white"
android:orderInCategory="201"
android:title="#string/overflow"
app:showAsAction="always">
<menu>
<item
android:id="#+id/cab_menu_select_all"
android:icon="#drawable/ic_select_all_grey"
android:orderInCategory="100"
android:title="#string/cab_menu_select_all"
app:showAsAction="always|withText"></item>
</menu>
</item>
try this code its works for you
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/action_search"
android:icon="#drawable/ic_action_search"
android:showAsAction="always"
android:title="#string/action_search"/>
<!-- Settings, should always be in the overflow -->
<item
android:id="#+id/action_location_found"
android:icon="#drawable/ic_action_location_found"
android:showAsAction="always"
android:title="#string/action_location_found"/>
<item
android:id="#+id/menu_overflow"
android:icon="#drawable/ic_action_menu"
android:orderInCategory="11111"
android:showAsAction="always">
<menu>
<!-- Refresh -->
<item
android:id="#+id/action_refresh"
android:icon="#drawable/ic_action_refresh"
android:showAsAction="ifRoom"
android:title="#string/action_refresh"/>
<!-- Help -->
<item
android:id="#+id/action_help"
android:icon="#drawable/ic_action_help"
android:showAsAction="never"
android:title="#string/action_help"/>
<!-- Check updates -->
<item
android:id="#+id/action_check_updates"
android:icon="#drawable/ic_action_refresh"
android:showAsAction="never"
android:title="#string/action_check_updates"/>
</menu>
</item>
</menu>
- See more at: http://www.theappguruz.com/blog/android-working-android-actionbar#sthash.ArNQTEBF.dpuf
Create your menu xml as follow
<item
android:id="#+id/menu_item_action_parameters"
android:title="#string/text_parameters"
android:icon="#drawable/ic_menu_parameter"
app:showAsAction="ifRoom|withText"/> >
<menu>
<item
android:id="#+id/action_dropdown1"
android:title="#string/dropdown_1" />
<item
android:id="#+id/action_dropdown2"
android:title="#string/dropdown2" />
<item
android:id="#+id/action_dropdown3"
android:title="#string/dropdown3" />
</menu>
</item>
<item
more item
</item>
Then
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
switch (id) {
case R.id.action_dropdown1:
.....
return true;
case R.id.action_dropdown2:
.....
return true;
.....
default:
return super.onOptionsItemSelected(item);
}
}
this is completely working code.Mark this answer up if it helps. :) Happy coding.
you Need to add tools:context="your class" to menu tag
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".activities.BaseActivity">
<item
android:id="#+id/action_notification1"
android:icon="#drawable/one"
android:title="action_notification"
app:showAsAction="always"/>
<item
android:id="#+id/action_notification2"
android:icon="#drawable/two"
android:title="action_notification"
app:showAsAction="always"/>
<item
android:id="#+id/action_notification3"
android:icon="#drawable/three"
android:title="action_notification"
app:showAsAction="always"/>
</menu>
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return super.onCreateOptionsMenu(menu);
}
you shold write tool:context to menu tag then run you will get icons to your text
I have two menu items in menu/contacts_menu.xml as :
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" >
<item
android:id="#+id/pm_action_search"
android:actionViewClass="android.widget.SearchView"
android:icon="#drawable/ic_action_search"
android:orderInCategory="1"
android:showAsAction="ifRoom|collapseActionView"
android:title="#string/action_search"/>
<item
android:id="#+id/show_online"
android:icon="#drawable/online_icon"
android:orderInCategory="2"
android:showAsAction="ifRoom"
android:title="Show Online"/>
</menu>
Where , in my Fragment :
#Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.contacts_menu, menu);
super.onCreateOptionsMenu(menu, inflater);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.show_online) {
// DO SOMETHING
return true;
}
return super.onOptionsItemSelected(item);
}
I have done the same procedure in my others apps, and action items are showing. But in my current app, they are not showing. only if i press the menu button, action items are showing only with text. i want to show the icons on my action bar.
I guess you are using appcompat library? Try this:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:appcompat="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/pm_action_search"
android:actionViewClass="android.widget.SearchView"
android:icon="#drawable/ic_action_search"
android:orderInCategory="1"
android:showAsAction="always|collapseActionView"
appcompat:showAsAction="always|collapseActionView"
android:title="#string/action_search" />
<item
android:id="#+id/show_online"
android:icon="#drawable/online_icon"
android:orderInCategory="2"
android:showAsAction="always"
appcompat:showAsAction="always"
android:title="Show Online" />
</menu>
This should definitely work, but for simplicity you can also try this:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:appcompat="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/pm_action_search"
android:actionViewClass="android.widget.SearchView"
android:icon="#drawable/ic_action_search"
android:orderInCategory="1"
appcompat:showAsAction="always|collapseActionView"
android:title="#string/action_search" />
<item
android:id="#+id/show_online"
android:icon="#drawable/online_icon"
android:orderInCategory="2"
appcompat:showAsAction="always"
android:title="Show Online" />
</menu>