0

How to show actionbar on higher Android version and menu in lower Android version?

Is this possible with one APK file.?

The version of the device that I am testing APK file is on Jelly Bean.

Here is the code that I tried.

Manifest.xml has:

   <uses-sdk
       android:minSdkVersion="9"
       android:targetSdkVersion="19" />

in My activity, I am calling this.

public class HomeActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
    setupActionBar();

...

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setupActionBar() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        getActionBar().setDisplayHomeAsUpEnabled(true);
        getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME
                | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM);
        getActionBar().show();
    }
}

My menu.xml looks like this

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
   <item
        android:id="@+id/action_refresh"
        android:orderInCategory="100"
        android:showAsAction="always"
        android:icon="@drawable/ic_refresh"
        android:title="Refresh"/>

  </menu>

Please suggest me. Thank you.

User12111111
  • 1,179
  • 1
  • 19
  • 41
  • Take a look at [this](http://developer.android.com/tools/support-library/features.html) or [this](http://actionbarsherlock.com/) – Campig Dec 23 '13 at 08:35
  • 1
    if you don't use the library, I think you will be able to achieve this. Because using the library with lower Android devices gives you an ActionBar by default. Even if you hide the ActionBar in lower devices, you will not get the menu items. – Rakeeb Rajbhandari Dec 23 '13 at 08:38
  • 1
    @user2247689 your comment should be the answer !! – LOG_TAG Dec 23 '13 at 08:41
  • For more info take a look at this http://stackoverflow.com/questions/7844517/difference-between-actionbarsherlock-and-actionbar-compatibility/18183801#18183801 – LOG_TAG Dec 23 '13 at 08:42

2 Answers2

0

If you want to show Action bar in a lower version of Android you will need to use use either Action bar compatibility library(Google code) or Action bar Sherlock library(third party code). Either one will help you to implement an Action bar in a lower version of Android.

Sean O'Toole
  • 4,304
  • 6
  • 35
  • 43
Mohan
  • 311
  • 8
  • 15
0

If you don't use the library, I think you will be able to achieve this. Because using the library with lower Android devices gives you an ActionBar by default. Even if you hide the ActionBar in lower devices, you will not get the menu items.

Rakeeb Rajbhandari
  • 5,043
  • 6
  • 43
  • 74