我已经编写了一个 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>
之前尝试过的步骤:
结果:
已经尝试,但仍然无法显示菜单。
结果:
菜单仍然没有出现。
结果:
从未添加该属性。
结果:
super.onCreateOptionsMenu(menu); is also added in the code but still the menu's don't appear.
我的问题是,我只想看到菜单而不是操作栏,可能的问题是什么?我没有收到任何错误信息,主要问题是我无法看到菜单本身。