Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Method call mActionBar=getActionBar() gives error [closed]

I am using support library android.support.v7.app.actionbar because i want action bar in api level 8 and above But following sentence gives me error like change mActionBar to ActionBar

mActionBar=getActionBar();

My FragmentActivity in which I wnat to use ActionBar Tab is as follows

import com.example.bottomtabadapter.TabPageAdapter;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBar.Tab;
import android.support.v7.app.ActionBarActivity;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import android.view.Menu;

public class TabFragmentActivity extends FragmentActivity implements ActionBar.TabListener{

private ViewPager mViewPager;
private ActionBar mActionBar;
private TabPageAdapter mAdapter;

private String[] tabs={"Chat","Groups","Contacts"};

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

    mViewPager=(ViewPager)findViewById(R.id.pager);
    mActionBar=getActionBar();  // here is the error
    mAdapter=new TabPageAdapter(getSupportFragmentManager());

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.tab, menu);
    return true;
}

@Override
public void onTabReselected(Tab arg0, FragmentTransaction arg1) {
    // TODO Auto-generated method stub

}

@Override
public void onTabSelected(Tab arg0, FragmentTransaction arg1) {
    // TODO Auto-generated method stub

}

@Override
public void onTabUnselected(Tab arg0, FragmentTransaction arg1) {
    // TODO Auto-generated method stub

}

}

like image 692
HemangNirmal Avatar asked Dec 20 '22 18:12

HemangNirmal


1 Answers

If you want to have action bar for old devices from API 7 and up you should maybe extend ActionBarActiviy

like image 193
donfuxx Avatar answered Dec 31 '22 14:12

donfuxx