Please help, I made a custom menu (added support libraries) (name-> main_activity_actions.xml)
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<item
android:id="@id/search"
android:icon="@drawable/search"
android:title="@string/search"
yourapp:showAsAction="ifRoom" />
<item
android:id="@id/view_all"
android:title="@string/view_all"
yourapp:showAsAction="never"/>
<item
android:id="@+id/action_settings"
yourapp:showAsAction="never"
android:title="@string/action_settings"/>
Now what should i do to put action_settings into three dots (of action bar), instead of hardware menu button (Without any hack).
MainActivity
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main_activity_actions, menu);
return true;
}
well i have found the hack but if there is any other way then let me know,
Hack
put this code in onCreate
try {
ViewConfiguration config = ViewConfiguration.get(this);
Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
if(menuKeyField != null) {
menuKeyField.setAccessible(true);
menuKeyField.setBoolean(config, false);
}
} catch (Exception ex) {
// Ignore
}
for this you need to import
import java.lang.reflect.Field;
import android.view.ViewConfiguration;
The kebab menu, also known as the three dots menu, and the three vertical dots menu, is an icon used to open a menu with additional options. The icon is most often located at the top-right or top-left of the screen or window. The picture shows an example of the kebab menu icon in Google Chrome.
To replace an app's default action bar with a Toolbar : Create a new custom theme and modify the app's properties so that it uses this new theme. Disable the windowActionBar attribute in the custom theme and enable the windowNoTitle attribute. Define a layout for the Toolbar .
Ellipsis = “More actions” More and more apps are now using a midline ellipsis (⋯) to indicate a menu with more actions. It basically means “Hey, there's more stuff you can do here.” In many Android apps, you'll often see a vertical ellipsis (⋮) to mean the same thing.
Without any hack, you cannot do that on all devices. Those devices that have the hardware menu button (I'm not sure if absolutely all) will use it instead of the overflow button (...).
Which, sort of, is a good thing. Users of those devices are used to pressing the menu button to get to the menu. So for them, the lack of the overflow button is the normal behaviour.
For those devices that use the overflow button, Android will decide itself what to put where based on your hints in showAsAction
tag. It depends on the screen size, orientation, among other things. This page has a table showing how many icons are displayed (the rest goes to overflow menu).
If you want to show the three dots, irrespective of device menu button! then you can call this method in your application class' onCreate method-
private void getOverflowMenu() {
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();
}
}
Please test This code for Display SherlokActionbar :
public class MainActivity extends SherlockActivity {
private com.actionbarsherlock.view.MenuItem mGoItem;
private com.actionbarsherlock.view.MenuItem mClearItem;
private static final int listSMS_ITEM_ID = 1;
private static final int Distance_ITEM_ID = 5;
private static final int About_ITEM_ID = 2;
private static final int Search_ITEM_ID = 3;
private static final int HELP_ITEM_ID = 4;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public boolean onCreateOptionsMenu(Menu menu) {
mGoItem = menu.add(0, HELP_ITEM_ID, 0, null);
mGoItem.setIcon(R.drawable.refresh).setShowAsAction(
MenuItem.SHOW_AS_ACTION_ALWAYS);
mGoItem = menu.add(0, Distance_ITEM_ID, 0, null);
mGoItem.setIcon(R.drawable.ic_launcher).setShowAsAction(
MenuItem.SHOW_AS_ACTION_ALWAYS);
mGoItem = menu.add(0, listSMS_ITEM_ID, 0, null);
mGoItem.setIcon(R.drawable.refresh).setShowAsAction(
MenuItem.SHOW_AS_ACTION_ALWAYS);
mGoItem = menu.add(0, Search_ITEM_ID, 0, null);
mGoItem.setIcon(R.drawable.ic_launcher).setShowAsAction(
MenuItem.SHOW_AS_ACTION_ALWAYS);
return true;
}
// @Override
public boolean onOptionsItemSelected(
com.actionbarsherlock.view.MenuItem item) {
// TODO Auto-generated method stub
/* return super.onOptionsItemSelected(item); */
switch (item.getItemId()) {
case listSMS_ITEM_ID:
Toast.makeText(getApplicationContext(), "listSMS", 1).show();
return true;
case Search_ITEM_ID:
Toast.makeText(getApplicationContext(), " Search", 1).show();
return true;
case Distance_ITEM_ID:
Toast.makeText(getApplicationContext(), " Distance", 1).show();
return true;
case HELP_ITEM_ID:
Toast.makeText(getApplicationContext(), " HELP", 1).show();
//
return true;
}
return false;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With