【问题标题】:how to create menu bar at bottom of the activity using 4.0.3 SDK如何使用 4.0.3 SDK 在活动底部创建菜单栏
【发布时间】:2014-01-31 06:44:32
【问题描述】:

我在 4.0.3 中创建一个菜单,根据文档,它总是在我的活动顶部显示菜单栏,但我想像这样在我的活动底部显示它。我怎样才能做到这一点?

目前我正在使用以下代码。

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>

主祭

<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>

并显示以下输出。

【问题讨论】:

  • 您正在使用平板电脑模拟器。我将很快提供一个解决方案,但不确定它能否在大屏幕上正常工作。

标签: android drop-down-menu menu contextmenu submenu


【解决方案1】:

据我所知,没有将ActionBar 完全移至底部的选项。但是仍然可以在底部显示一些项目。为此,您需要这样做:

  • 只需将android:uiOptions="splitActionBarWhenNarrow" 添加到AndroidManifest.xml 中的activity 标记,就像这样...

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

你可以阅读更多herehere

希望对您有所帮助。 :)

【讨论】:

  • 它不工作我也使用它但它不工作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-04-03
  • 1970-01-01
  • 1970-01-01
  • 2016-03-22
  • 1970-01-01
  • 2011-09-08
  • 1970-01-01
相关资源
最近更新 更多