Is it possible to create on option menu but have it at the bottom of the page. I'm working with <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" />. I know that by default it is position at the top, but im assuming it can be bought to the bottom. I just dont know how .
here is my code
option_menu.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/scan"
android:icon="@android:drawable/ic_menu_search"
android:title="@string/connect"/>
<item android:id="@+id/discoverable"
android:icon="@android:drawable/ic_menu_mylocation"
android:title="@string/discoverable"/>
</menu>
main.java
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.option_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.scan:
// Launch the DeviceListActivity to see devices and do scan
Intent serverIntent = new Intent(this, DeviceListActivity.class);
startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE);
return true;
case R.id.discoverable:
// Ensure this device is discoverable by others
ensureDiscoverable();
return true;
}
return false;
}
Any help would be great.
Seeing that you target sdk 17, you can use the SplitBar, it is an option available on the default ActionBar: http://developer.android.com/guide/topics/ui/actionbar.html#SplitBar.
You need to declare it in every activity where it is needed in your manifest file, for example:
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main"
android:uiOptions="splitActionBarWhenNarrow" />
Then in your onCreate function, you can also call a custom layout if you still need to display additional buttons at the top of the screen:
ActionBar actionBar = getActionBar();
actionBar.setCustomView(R.layout.action_bar_custom); //load menu
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME|ActionBar.DISPLAY_SHOW_CUSTOM);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.show();
By default, the icons displayed normally at the top will be displayed at the bottom, but you can still add custom action buttons using a custom layout such as the one in this example.
The setDisplayOptions function is described here.
EDIT: the menu will be displayed at the bottom only on narrow screens, on bigger devices or in landscape mode, the default action bar at the top will be displayed.
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