I am working in an app with this kind of structure:
The app has no initial ActionBar so I add it on the OnCreate on each Activity this way:
android.support.v7.widget.Toolbar barra =(android.support.v7.widget.Toolbar) getLayoutInflater().inflate(local.quick_stuff.R.layout.barra_herramientas,null);
LinearLayout layout_actividad = (LinearLayout)findViewById(R.id.cp_lista_receta);
layout_actividad.addView(barra,0);
setSupportActionBar(barra);
getSupportActionBar().setTitle("Listado de Recetas");
Then I try to inflate a menu.xml to the ActionBar so the code changes to this:
android.support.v7.widget.Toolbar barra =(android.support.v7.widget.Toolbar) getLayoutInflater().inflate(local.quick_stuff.R.layout.barra_herramientas,null);
barra.inflateMenu(R.menu.menu_barra);
LinearLayout layout_actividad = (LinearLayout) findViewById(R.id.cp_lista_receta);
layout_actividad.addView(barra,0);
setSupportActionBar(barra);
getSupportActionBar().setTitle("Listado de Recetas");
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
But the result is a blank ActionBar
The Menu.xml file
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/filtro"
android:icon="@drawable/filtrado_icono"
android:title="Filtrado"
android:visible="true"
app:showAsAction="ifRoom"/>
</menu>
At the end of the day i am trying to do this to have flexibility because a want to have different menu.xml to inflate at my ActionBar. I am thinking this could be kind of flexible but has too many branching coding.
Any help?