Reputation: 13
I can't find the overflow menu in the android studio 2.0. How can i find it and to add it to my activity? The menu ia the one with three dots. I tried to change the theme of the activity but it didn't worked. I also tried to change the api of the android from the setting of the android studio but it didn't worked. please help me here im trying alot but I can't find it.
here is the menu that im talking about
Upvotes: 0
Views: 263
Reputation: 100
To get Three dot overflow menu at Android Title Bar, you can follow below steps.
STEP 1 : In layout\activity_main.xml Add below code
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
STEP 2 : At activity\MainActivity.java
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_mainactivity, menu);
return true;
}
STEP 3: Add below code at menu\menu_mainactivity.xml, this code shows RATE, CONTACT, ABOUT Menu items
<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="Your Activity Package Name">
<item
android:id="@+id/action_rate_it"
android:orderInCategory="100"
android:title="@string/action_rate_it"
app:showAsAction="never" />
<item
android:id="@+id/action_contact_us"
android:orderInCategory="100"
android:title="@string/action_contact"
app:showAsAction="never" />
<item
android:id="@+id/action_about"
android:orderInCategory="100"
android:title="@string/action_about"
app:showAsAction="never" />
</menu>
STEP 4 : At AndroidManifest.xml, Your main activity should have "android:theme="@style/AppTheme.NoActionBar"" i.e. Like
<activity android:name=".MainActivity"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
STEP 5: at values\styles.xml should have below style in resource tag
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
Above code will add THREE DOTS Menu with Rate, Contact & About menu.
Upvotes: 1