Here I am going to explain how to show the overflow menu even if the phone has an options button
Step 1).Paste the below code in onCreate() method
try
{
ViewConfiguration config = ViewConfiguration.get(this);
Field menuField= ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
if (menuField != null)
{
menuField .setAccessible(true);
menuField .setBoolean(config , false);
}
} catch (Exception e)
{
}
Step 2).res->menu->main.xml
<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="com.ifin.MainActivity" >
<item
android:id="@+id/profile"
android:title="Profile"/>
<item
android:id="@+id/contact"
android:title="Contact Us"/>
<item
android:id="@+id/action_ad"
android:title="Logout"/>
</menu>
Happy Coding:)

No comments:
Post a Comment