Click here to Skip to main content
15,882,163 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have been trying out an application I made and the action bar works on my 4.4 version. The ation bar doesn't show on the 4.3 version.

This is what I'm using:

CSS
<uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />




private static final int ABOUTUS = Menu.FIRST + 1;
private static final int CLOSE = Menu.FIRST + 2;


@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(Menu.NONE, ABOUTUS, Menu.NONE, "About Us");
menu.add(Menu.NONE, CLOSE, Menu.NONE, "Exit");

return (super.onCreateOptionsMenu(menu));
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case ABOUTUS:
Intent intent = new Intent(this, AboutUs.class);
startActivity(intent);
break;
case CLOSE:
finish();
break;

default:
finish();
break;
}
return (super.onOptionsItemSelected(item));
}

}

I have the appcombat_V7 imported in my workspace.

Not really sure why this is happening but any help received will be much appreciated.
Posted

1 solution

Firstly, in the activities that use the AppCompat ActionBar you need to import the necessary classes.

import android.support.v7.app.ActionBarActivity;
   import android.support.v4.app.Fragment;
   import android.support.v7.app.ActionBar;
//if you need to customize the ActionBar

Secondly, each *activity* must extend the ActionBarActivity class.

//say
public class MainActivity extends ActionBarActivity {


Thirdly, you need to declare the right theme in the styles.xml files in the various values/values-v11 folders.

<style name="AppBaseTheme" parent="Theme.AppCompat.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>

For *styles.xml* in **values-v14** folder :

<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- API 14 theme customizations can go here. -->
    </style>


If you have done things this way already, then I would like to add that the basic template created using the *New -> Other -> Android -> Android Application Project* option and setting the android:minSdkVersion="8" works well with Android 4.3 on the emulator and on devices. I have tested this and suggest you use this as a reference.
 
Share this answer
 
v2
Comments
developerjm 2-Sep-14 14:51pm    
Thanks for your reply. But unfortunately still no luck! :/

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900