How to add a line between items in the title bar of an application menu bar in Android Studio?

I have a menu in the title bar of my Android app that is not a popup menu. I have some items in it. I want to add a string or separator between one pair of items in a list. I do not need separators between all elements, just one pair. I tried with groups that have different identifiers, did not work, also tried with android: actionlayout, without success.

My current menu looks like this in design mode. I want to do something like this .

My XML containing my menu:

<?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"> <item android:title="@string/editare_nume_jucatori"> <!-- submeniul meu --> <menu> <item android:id="@+id/M_Jucator1" android:enabled="true" android:title="@string/Jucatorul1" /> <item android:id="@+id/M_Jucator2" android:enabled="true" android:title="@string/Jucatorul2" /> </menu> </item> <item android:id="@+id/M_Detalii" android:icon="@drawable/dice10" android:title="@string/detalii_text_meniu" /> <item android:id="@+id/M_Despre_Aplicatie" android:icon="@drawable/dice10" android:title="@string/despre_aplicatie" /> <item android:id="@+id/M_Iesire_Aplicatie" android:icon="@drawable/m3" android:title="@string/IesireAplicatie" /> </menu> 

My Java code for the menu:

 Menu meniu1; //a variable used in my menu //to show my menu @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.meniul_meu, menu); meniu1 = menu; //this is my variable from up declaration return true; } //here execute different actions for items clicked in menu @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle item selection switch (item.getItemId()) { //click on my item ID from menu and execute case R.id.M_Jucator1: ...(code code)... return true; //click on my item ID from menu and execute case R.id.M_Jucator2: ..(code code)... return true; //click on my item ID from menu and execute case R.id.M_Detalii: ..(code code)... return true; //cand dai click pe iesire din meniu case R.id.M_Iesire_Aplicatie: ..(code code).. return true; default: return super.onOptionsItemSelected(item); } } //finish meniu codes 
+5
source share

Source: https://habr.com/ru/post/1262151/


All Articles