开发者

Android Action Bar Problem

开发者 https://www.devze.com 2023-04-09 03:42 出处:网络
I am trying to implement a action bar in my app.I followed the methodfrom this link http://developer.android.com/guide/topics/ui/acti开发者_开发百科onbar.html If I keep the tragetSdkversion>= 11,Then

I am trying to implement a action bar in my app.I followed the method from this link http://developer.android.com/guide/topics/ui/acti开发者_开发百科onbar.html If I keep the tragetSdkversion>= 11,Then it works fine. But If I add min sdk version>=11 then the buttons shows up as part of the options menu and not in the action bar. This happens for the tablet.please help

This is part of my manifest

<uses-sdk android:minSdkVersion="4" 
        android:targetSdkVersion="11"/>

This is my menu.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/edit"
        android:title="Edit"
        android:icon="@drawable/icon"
        android:showAsAction="ifRoom" />

    <item android:id="@+id/renarration"
        android:title="Renarration"
        android:icon="@drawable/icon" 
        android:showAsAction="ifRoom"/>

    <item android:id="@+id/renarration1"
        android:title="Renarration"
        android:icon="@drawable/icon" 
        android:showAsAction="ifRoom"/>

    <item android:id="@+id/renarration2"
        android:title="Renarration"
        android:icon="@drawable/icon" 
        android:showAsAction="ifRoom"/>
</menu>


In the same link you're referring it says,

The Action Bar is included by default in all activities that target Android 3.0 or greater. Any application that targets Android 3.0 automatically receives this theme. An application is considered to "target" Android 3.0 when it has set either the android:minSdkVersion or android:targetSdkVersion attribute in the element to "11" or greater.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.example.helloworld"
  android:versionCode="1"
  android:versionName="1.0">
<uses-sdk android:minSdkVersion="4"
          android:targetSdkVersion="11" />
<application ... >
    ...
</application>

In this example, the application requires a minimum version of API Level 4 (Android 1.6), but it also targets API Level 11 (Android 3.0). This way, when the application is installed on a device running Android 3.0 or greater, the system applies the holographic theme to each activity, and thus, each activity includes the Action Bar.

However, if you want to use Action Bar APIs, such as to add tabs or modify Action Bar styles, you need to set the android:minSdkVersion to "11", so you can access the ActionBar class.


If I keep the tragetSdkversion>= 11,Then it works fine. But If I add min sdk version>=11 then the buttons shows up as part of the options menu and not in the action bar.

=> Action bar is possible only in Android 3.0 or greater.

Haven't you marked the description clearly written in the link you have mentioned:

The Action Bar is included by default in all activities that target Android 3.0 or greater

you can find this line in "Adding the Action Bar" section.

More specifically, all activities that use the new "holographic" theme include the Action Bar, and any application that targets Android 3.0 automatically receives this theme. An application is considered to "target" Android 3.0 when it has set either the android:minSdkVersion or android:targetSdkVersion attribute in the element to "11" or greater. (From Android doc)


The latest Android Support Library (18) now supports ActionBars back to API 7 (2.1). It is contained in android.support.v7.appcompat. See Android Support Library and ActionBarActivity for more information.

0

精彩评论

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

关注公众号