开发者

ActionBar not being created even with min SDK version set to 11

I have my min SDK version set to 11 and my target SDK version set to 11. I have an activity with some fragments in it. The style has parent="@android:style/Theme.Light" and doesn't hide the actionbar. In the activity where I expect to see the actionbar, I have an override of onCreateOptionsMenu(). My understanding is that onCreateOptionsMenu() will automatically be called when the activity starts and that will create the actionbar. This is not happening for me. I'm not sure if my understanding is wrong or if I'm doing something wrong that is causing it not to show up.

To be clear, my onCreateOptionsMenu method is not even firing. I suspect the problem is in another part of the开发者_开发技巧 code, but I don't know what it could be.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.signin_layout_menu, menu);
    return true;
}

Here is my menu xml:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/menu_signin_layout"
         android:title="stuff"
         android:showAsAction="ifRoom|withText" />
</menu>

Here is the style that activity is using:

<style name="Theme.MyTheme" parent="@android:style/Theme.Light">
    <!-- Window attributes -->
    <item name="android:windowTitleSize">36dip</item>
    <item name="android:windowTitleStyle">@style/WindowTitle</item>
    <item name="android:windowTitleBackgroundStyle">@style/WindowTitleBackground</item>

    <item name="android:textAppearanceButton">@style/TextAppearance.Widget.Button</item>

    <!-- Button styles -->
    <item name="android:buttonStyle">@style/Widget.Button</item>
</style>


I'm pretty sure your theme needs to be parent="@android:style/Theme.Holo.Light" for the actionbar to show.


Are you inflating the menu and returning "true", to indicate that you've handle the action, correctly in your onCreateOptionsMenu() override? http://developer.android.com/guide/topics/ui/menus.html#Inflating

If you're returning false, the event will bubble up to the parent, which by default does nothing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜