3 Dot Setting Menu For Android Apps With Custom Title
Solution 1:
As @dumazy pointed out that the Action bar's Menu Overflow icon is only shown on those devices which do not have a hardware menu-button.
How do I know when it is needed? meaning phones that don't have the settings button
This is handled by Android itself. You don't need to worry.
how do i create a context menu that is customized and attached to the 3 dot button
You can just have a an xml file inside Menu
folder in res
. Then you can specify the xml file inside the MenuInflater. Eg:
lets name it list_menu.xml
?xml version="1.0" encoding="utf-8"?>
<menuxmlns:android="http://schemas.android.com/apk/res/android" ><itemandroid:id="@+id/menu_item_1"android:title="@string/menu_string_1"android:showAsAction="ifRoom|withText"/><itemandroid:id="@+id/menu_item_1"android:title="@string/menu_string_2"android:showAsAction="ifRoom|withText"/></menu>
In the onCreateOptionsMenu
you can set it as:
publicbooleanonCreateOptionsMenu(Menu menu) {
MenuInflatermi= getMenuInflater();
mi.inflate(R.menu.list_menu, menu);
returntrue;
}
This menu would be attached to the overflow-icon and have the items that you want to show when it is clicked. There are some hacks like this which can show the overflow-icon on all devices but using them is highly discouraged. Let android handle this itself.
You seem to use Title bar. Instead, try to use Action Bar for the same.
Hope this answers your question.
Solution 2:
how do I know when it is needed? meaning phones that don't have the settings button
Call hasPermanentMenuKey()
on a ViewConfiguration
.
also how do i create a context menu that is customized and attached to the 3 dot button
By programming. Since you are not using an action bar, it is impossible to give you specific advice that would be relevant.
Solution 3:
Google says Actionbar overflow only appears on phones that have no menu hardware keys. Phones with menu keys display the action overflow when the user presses the key. If you still want to implement this you may follow this solution.
Click here for your reference.
Just copy this method in your activity and call the method from onCreate method
privatevoidgetOverflowMenu() {
try {
ViewConfiguration config = ViewConfiguration.get(this);
Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
if(menuKeyField != null) {
menuKeyField.setAccessible(true);
menuKeyField.setBoolean(config, false);
}
} catch (Exception e) {
e.printStackTrace();
}
}
Post a Comment for "3 Dot Setting Menu For Android Apps With Custom Title"