Thursday, December 5, 2019

OverFlow/3 Dots Menu Android

Create an Overflow menu inside Activity and Fragment.
@SuppressLint("RestrictedApi")
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    menu.clear();
    getMenuInflater().inflate(R.menu.all_page_menu, menu);
    if(menu instanceof MenuBuilder) {  
        MenuBuilder m = (MenuBuilder) menu;
        m.setOptionalIconsVisible(true);
    }
    return true;
}
From this Link.
OR
Create a menu like this. Here ic_more_vert is 3 dot image.
<?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">

    <item
        android:id="@+id/none"
        android:icon="@drawable/ic_more_vert"
        android:title=""
        app:showAsAction="always">

        <menu>

            <item
                android:id="@+id/home"
                android:icon="@drawable/home"
                android:title="HOME" />       

        </menu>
    </item>


    <item
        android:id="@+id/add"
        android:icon="@drawable/plus_white"
        android:orderInCategory="100"
        android:title="Add"
        app:showAsAction="always" />

</menu>
That is all. If any help related to this post please comment.

Thank you, guys.

Enjoy coding.

No comments:

Post a Comment