Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View between menu items in toolbar

Is it possible to take view in menu items of toolbar?

I want view like shown in yellow color between two menu items of toolbar.

like image 541
Salman khan Avatar asked May 10 '26 04:05

Salman khan


1 Answers

Simply create a divider line view in xml file to show a divider line.

dividerLine.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<View
android:layout_width="1dp"
android:layout_height="?android:attr/actionBarSize" 
android:background="@android:color/darker_gray"/> 
 </LinearLayout>

and set actionLayout to an item in menu xml to show divider line

activity_menu.xml

 <menu xmlns:android="http://schemas.android.com/apk/res/android" >

<item android:id="@+id/your_icon1"
      android:icon="@drawable/image1"
      android:title="@string/text1"
      app:showAsAction="always"
      />

<item android:id="@+id/icon2TricktoShowDividerLine"
     android:actionLayout="@layout/dividerLine" 
     app:showAsAction="always"
     android:title="@string/text2" />

<item android:id="@+id/your_icon3"
      android:icon="@drawable/icon"
      android:title="@string/text3"
      app:showAsAction="always" />
 </menu>

android:actionLayout="@layout/dividerLine" shows divider line between menu items. Hope this helps you.

Updated

I am getting this type of view from my above code :

enter image description here

like image 152
Kapil Rajput Avatar answered May 11 '26 18:05

Kapil Rajput



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!