How can I use getSupportActionBar in FragmentActivity?

It says it ActionBarActivity

is a subclass FragmentActivity

, but in my FragmentActivity, I cannot use getSupportActionBar()

.
It works well when it extends ActionBarActivity, but I need exactly FragmentActivity for other things. I tried using ActionBar v7 but it gives me a NullPointerException also tried other things written here like:

 ActionBar actionBar = ((ActionBarActivity)getActivity()).getSupportActionBar;

      

but none of them worked.

package com.example.campusinfo;

import android.graphics.Typeface;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.widget.TextView;

public class ActivityTab extends FragmentActivity{

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

        getSupportActionBar().setBackgroundDrawable(new ColorDrawable(0xff1699d1));
        getSupportActionBar().setDisplayShowTitleEnabled(false);
        getSupportActionBar().setCustomView(R.layout.title_activity);
        getSupportActionBar().setDisplayShowCustomEnabled(true);

        TextView tv = (TextView) findViewById(R.id.activity_title);
        tv.setTextSize(35f);
        Typeface face = Typeface.createFromAsset(getAssets(), "fonts/capriola.ttf");
        tv.setTypeface(face);
    }

}

      

+3


source to share


2 answers


Just stretch ActionBarActivity

out and you can do whatever you want there



+4


source


Use ActionBarActivity

and then use polymorphism for other stuff you want to use FragmentActivity

.



0


source







All Articles