I'm using Android Studio for the first time and can't manage to make the ActionBar
show when I run the app. Here's what I have so far:
My Activity MainActivity.java
package xeniasis.mymarket;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.support.v7.app.ActionBar;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return super.onCreateOptionsMenu(menu);
}
}
it's layout activity_main.xml (nothing there)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="xeniasis.mymarket.MainActivity"></RelativeLayout>
and the menu with one item activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="xeniasis.mymarket.MainActivity">
<item
android:id="@+id/action_update"
android:icon="@drawable/ic_action_update"
android:showAsAction="ifRoom"
android:title="@string/update_app" />
</menu>
Do I need something else in order to show the ActionBar
?
EDIT
here is the app theme
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
you must call you actionBar almost similar to how you would inflate a view and remember to use tool bar