Reputation: 71
It says that ActionBarActivity
is a subclass of FragmentActivity
, but in my FragmentActivity I can't use getSupportActionBar()
.
It works well when it extends ActionBarActivity, but I need exactly FragmentActivity for other stuff. I tried to use ActionBar v7, but it gives me 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);
}
}
Upvotes: 3
Views: 6769
Reputation:
Just extend ActionBarActivity
, and you can do all you want to do there
Upvotes: 4
Reputation: 2249
Use ActionBarActivity
and then use polymorphism for the other stuff you want to use FragmentActivity
in.
Upvotes: 0