我有一個main.xml
定義爲:動作條不顯示的菜單項
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/notifications"
android:icon="@drawable/ic_notifications"
android:title="@string/notifications" />
<item
android:id="@+id/reportsView"
android:icon="@drawable/ic_reports"
android:showAsAction="always"
android:title="@string/reportsView" />
<item
android:id="@+id/userProfile"
android:icon="@drawable/ic_profile"
android:title="@string/userProfile" />
</menu>
而且在活動我有這樣的:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
但我仍不能看到我的動作欄上的按鈕。誰能告訴我缺少什麼
styles.xml
:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<style name="FullscreenTheme" parent="android:Theme.NoTitleBar">
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowBackground">@null</item>
<item name="metaButtonBarStyle">@style/ButtonBar</item>
<item name="metaButtonBarButtonStyle">@style/ButtonBarButton</item>
</style>
<style name="ButtonBar">
<item name="android:paddingLeft">2dp</item>
<item name="android:paddingTop">5dp</item>
<item name="android:paddingRight">2dp</item>
<item name="android:paddingBottom">0dp</item>
<item name="android:background">@android:drawable/bottom_bar</item>
</style>
<style name="ButtonBarButton" />
</resources>
什麼主題? – Simas
我已經更新了我的問題了'機器人:主題= 「@風格/ AppTheme」' – Maven
您正在試圖誇大** ** main.xml中,而不是menu.xml文件:'getMenuInflater()膨脹(R.menu.main ,菜單);'。將menu.xml重命名爲'main.xml' **或**將infaltion更改爲'getMenuInflater()。inflate(R.menu.menu,menu);'。 –