我正在使用支持库android.support.v7.app.actionbar
,因为我想要 api level 8 及更高版本中的操作栏
但是下面的句子给我一个错误,比如将mActionBar改为ActionBar
mActionBar=getActionBar();
我的 FragmentActivity ,我想使用 ActionBar 标签,如下所示
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
}
}
答案 0 :(得分:6)
如果您想为API 7及更高版本的旧设备设置操作栏,您可以延长ActionBarActiviy
答案 1 :(得分:5)
尝试使用姜饼代码。别忘了添加支持的库
public class NavigationActivity extends ActionBarActivity {
ActionBarActivity activity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.slide_screen);
activity=(ActionBarActivity) Context.getApplicationContext();
ActionBar actionBar = getSupportActionBar();
}