【发布时间】:2016-06-21 03:07:12
【问题描述】:
我已经为 Android 中的菜单编写了代码,但它现在显示在我的活动中,这是我的代码
我这里只显示我的相关代码,
Manifest.xml
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppBaseTheme" >
MainActivity.Java
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.
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
switch (item.getItemId()) {
// Some action here
}
}
}
main.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.androidex1.MainActivity" >
<item android:id="@+id/item1"
android:title="one" />
<item android:id="@+id/item2"
android:title="two" />
<item android:id="@+id/item3"
android:title="three" />
<item android:id="@+id/item4"
android:title="four" />
</menu>
之前尝试过的步骤
Menu Items are not showing on Action Bar
结果:
尝试过但仍然没有出现菜单
Android options menu not displaying
结果:
菜单仍然没有出现。
结果:
从未添加过该属性。
Option Menu does not appear in Android
结果:
super.onCreateOptionsMenu(menu); is also added in the code but still the menu's don't appear.
我的问题 我只想看到菜单而不是操作栏,可能是什么问题?我没有收到任何错误,主要问题是我看不到菜单本身。
【问题讨论】:
-
好的,我建议使用Android Studio!你看到我的帖子了吗?我编辑它...
-
@Dario 在 Studio 中尝试过相同的操作,但不明白发生了什么?还是看不到简单的菜单
-
你能发布一些你的应用程序的图片吗?添加更多信息,以便我们了解问题所在!我简单地创建一个新项目,使用您的代码创建一个 menu.xml,将菜单添加到活动中,如果我按下手机 Galaxy S3 中的菜单按钮,我会看到菜单的 3 个选项。与 android studio 中的 nexus 7 的 AVD 相同。建议使用最新版本SDK更新的android studio再试一次。
-
发布您的结果图片和您期望的图片,如果可以的话!