Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Option menu with lines between options.like a divider between options that are displayed in menu

Tags:

In my application i have option menu which is placed in top as default.When we press that menu will open in that menu their is no lines between options.i want to display lines between then like a divider.

I try to change theme it work but i wont an other solution because if i change theme it will effect my application totally.

it is work in AppTheme not in AppTheme.AppCompat.

i want it is work with out change in themes.

If any one want code i will post it.

 <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:showDividers">beginning</item>
    <item name="android:divider">@color/action_bar_divider</item>
</style>
like image 237
Bhargavi Yamanuri Avatar asked Jul 21 '16 04:07

Bhargavi Yamanuri


1 Answers

There is many ways to achieve this.

solution 1 ==> you can make group in menu xml like below

<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">

<group android:id="@+id/grp1">
<item
    android:id="@+id/navigation_item_1"
    android:checked="true"
    android:icon="@drawable/ic_home"
    android:title="@string/navigation_item_1" /></group>

<group android:id="@+id/grp2">
<item
    android:id="@+id/navigation_item_2"
    android:icon="@drawable/ic_home"
    android:title="@string/navigation_item_2" /></group></menu>

solution 2==> you can make custom action layout like below

<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">
<item
    android:id="@+id/action_cart"
    android:title="cart"
    android:actionLayout="@layout/custom_layout"
    android:icon="@drawable/shape_notification"
    app:showAsAction="always"/>

and actionLayout file like below

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

<View
    android:id="@+id/divider"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/divider"/>

<TextView
    android:id="@android:id/text"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?android:attr/selectableItemBackground"
    android:gravity="center_vertical"          
    android:textAppearance="?attr/textAppearanceListItemSmall"/>

solution 3 ==> you can make custom theme for particular activity

<style name="CustomTheme" parent="android:Theme.Holo.Light">
<item name="android:actionBarStyle">@style/ActionBar</item></style>


 <style name="ActionBar"parent="android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">@color/action_bar_background</item>
<item name="android:showDividers">beginning</item>
<item name="android:divider">@color/action_bar_divider</item></style>

solution 4==> you can custom view for DropdownlistView

<style name="PopupMenuListView" parent="@style/Widget.AppCompat.ListView.DropDown">
<item name="android:divider">#000000</item>
<item name="android:dividerHeight">1dp</item>
</style>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">   


 <item name="android:dropDownListViewStyle">@style/PopupMenuListView</item></style>

you can refer this link add divider in menu item

like image 178
Vishal Thakkar Avatar answered Sep 28 '22 03:09

Vishal Thakkar