how to create menu bar at bottom of the activity using 4.0.3 SDK

倖福魔咒の 提交于 2019-12-23 03:37:09

问题


I am creating a menu in 4.0.3, according to documentation it always shows menu bar at the top of my activity but i want to show it at the bottom of my activity like that.How can i achieve this?

Currently i am using the following code.

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

@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, menu);
    return true;
}}

menue.xlm

<menu xmlns:android="http://schemas.android.com/apk/res/android" >


<item
    android:id="@+id/weather"
    android:showAsAction="always|withText"
    android:icon="@drawable/ic_launcher"
    android:title="weather"/>
<item
    android:id="@+id/second"
    android:icon="@drawable/ic_launcher"
    android:showAsAction="always|withText"
    android:title="Home"/>

<item
    android:id="@+id/java"
    android:icon="@drawable/ic_launcher"
    android:showAsAction="always|withText"
    android:title="Java"/>

<item
    android:id="@+id/android"
    android:icon="@drawable/ic_launcher"
    android:showAsAction="always|withText"
    android:title="Android"/>
</menu>

Mainfest

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.bottom.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

and it showing the following output.


回答1:


As far as i know there is no option to move the ActionBar entirely to the bottom. But still it is possible to display few items at the bottom. for that you need to do this:

  • Just add android:uiOptions="splitActionBarWhenNarrow" to your activity tag in theAndroidManifest.xml like this...

    <activity android:name=".MainActivity" android:uiOptions="splitActionBarWhenNarrow">

You can read more here and here

Hope it helps. :)



来源:https://stackoverflow.com/questions/21474026/how-to-create-menu-bar-at-bottom-of-the-activity-using-4-0-3-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!