Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes! You can definitely do this. Try following the pattern outlined below.</p> <p>In your <code>AndroidManifest.xml</code> file declare the following (replacing the platform versions with whatever your app requires):</p> <pre><code>&lt;!-- Build Target --&gt; &lt;uses-sdk android:targetSdkVersion="14" android:minSdkVersion="7" /&gt; </code></pre> <p>By targeting a platform version of API 11 or higher, you are allowing Eclipse to link (compile) against the native ActionBar classes. Providing an earlier minimum platform version allows your app to be installed (run) on older versions of Android.</p> <p>Your Activity code should then look something like this:</p> <pre><code>@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (CompatibilityManager.isHoneycomb()) { final ActionBar actionBar = getActionBar(); actionBar.setDisplayShowHomeEnabled(true); // ... } else { // The ActionBar is unavailable! // ... } } </code></pre> <p>Where the <code>CompatibilityManager.java</code> class simply provides static helper methods for determining the current version of the SDK:</p> <pre><code>public class CompatibilityManager { public static final String KINDLE_FIRE_MODEL = "Kindle Fire"; /** * Get the current Android API level. */ public static int getSdkVersion() { return android.os.Build.VERSION.SDK_INT; } /** * Determine if the device is running API level 11 or higher. */ public static boolean isHoneycomb() { return getSdkVersion() &gt;= Build.VERSION_CODES.HONEYCOMB; } /** * Determine if the device is running API level 14 or higher. */ public static boolean isIceCreamSandwich() { return getSdkVersion() &gt;= Build.VERSION_CODES.ICE_CREAM_SANDWICH; } /** * Determine if the current device is a first generation Kindle Fire. * @return true if the device model is equal to "Kindle Fire", false if otherwise. */ public static boolean isKindleFire() { return Build.MODEL.equals(KINDLE_FIRE_MODEL); } } </code></pre> <p>You might also consider leveraging the <a href="http://actionbarsherlock.com/" rel="noreferrer">ActionBarSherlock</a> library, which provides a compatible ActionBar API all the way back to Android 2.x:</p> <blockquote> <p>The library will automatically use the native action bar when available or will automatically wrap a custom implementation around your layouts. This allows you to easily develop an application with an action bar for every version of Android back through 2.x.</p> </blockquote> <p>Have fun!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload