Problems displaying ActionBar


#1

Hi All,

Long time listener, first time posted.

I’m working my way through the CriminalIntent App in Chapter 8 but I notice that my action bar does not display. I assume that you need to extent ActionBarActivity but in reading the directions, I don’t see this stipulated at any point and CrimeListFragment needs to extend FragementActivity (code as follows)

package com.example.criminalintent;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;

public abstract class SingleFragmentActivity extends FragmentActivity {
protected abstract Fragment createFragment();

@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_fragment);

	FragmentManager fm = getSupportFragmentManager();
	Fragment fragment = fm.findFragmentById(R.id.fragmentContainer);
			
	if (fragment == null) {
		fragment =  createFragment();
		fm.beginTransaction()
		.add(R.id.fragmentContainer, fragment)
		.commit();
	}
	
}

}

also style file as follows…

<!--
    Base application theme, dependent on API level. This theme is replaced
    by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!--
        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>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>

any help would be gratefully appreciated , as its driving me nuts :slight_smile:

Thanks,
Paul


#2

Hello,

Are you using AndroidStudio or Eclipse? I am having the same issue but I don’t remember this being an issue with Eclipse.

My solution, unless you found another is to change values/styles.xml:

Do you have another solution?

#3

HI There,

I’m using Eclipse and Andriod 5.0.1. Unfortunately the above fix doesnt work for me, see below…

<!--
    Base application theme, dependent on API level. This theme is replaced
    by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!--
        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>

<!-- Application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>

In previous examples the ActionBar had to be painted onto the screen, and it worked find for GEOQuiz by extending ActionBarActivity. Any help would we gratefully appreciated?

Paul


#4

I believe this book was written before ActionBarActivity was introduced to Android; ActionBarActivity is merely the support library’s way of providing an action bar to versions of Android that don’t support it. It actually extends FragmentActivity, so your SingleFragmentActivity should be able to extend ActionBarActivity to see get an action bar.

developer.android.com/reference … ivity.html