找不到符号法getSupportActionBar() [英] cannot find symbol method getSupportActionBar()

查看:2866
本文介绍了找不到符号法getSupportActionBar()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题已经发布很多次,但我还是无法解决从连我已经尝试了许多解决方案的堆栈溢出

 进口android.support.v4.app.FragmentActivity;
进口android.support.v4.app.FragmentManager;
进口android.support.v4.app.FragmentTransaction;
进口android.support.v7.app.ActionBar;
进口android.support.v7.app.ActionBarActivity;
进口com.example.project.myapplication.API​​.InfoAPI;
进口com.example.project.myapplication.Adapter.TabsFragmentPagerAdapter;
公共类编辑扩展FragmentActivity实现ActionBar.TabListener {    私人ViewPager viewPager;
    私人动作条动作条;
    私人TabsFragmentPagerAdapter tabsAdapter;
    私有String [] =活动新的String [] {信息,工作队,工作内容};
    ListView的listViewEdit;
    InfoAPI sqlcon;
    私人MyDatabaseHelper dbHelper;
    私人SQLiteDatabase数据库;
    私人SimpleCursorAdapter DataAdapter的;    @覆盖
    公共无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.edit);
        viewPager =(ViewPager)findViewById(R.id.viewPager);
        tabsAdapter =新TabsFragmentPagerAdapter(getSupportFragmentManager());
        viewPager.setAdapter(tabsAdapter);
        动作条=(ActionBarActivity)getApplicationContext()getSupportActionBar()。
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        的for(int i = 0;我3;;我++){
            actionBar.addTab(actionBar.newTab()的setText(活动[I])setTabListener(本)。);
        }

错误是在这一行动作条=(ActionBarActivity)getApplicationContext()getSupportActionBar();

错误

 错误:(48 63)错误:无法找到符号法getSupportActionBar()
错误:(48 21)错误:不兼容的类型:ActionBarActivity不能转换为动作条


解决方案

修改延长 AppCompatActivity 而不是 FragmentActivity AppCompatActivity 扩展 FragmentActivity ,并添加了对动作条支持。你可以阅读更多

I know this question has been posted plenty of times, but I still unable to solve even i have tried many solution from Stack Overflow.

import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import com.example.project.myapplication.API.InfoAPI;
import com.example.project.myapplication.Adapter.TabsFragmentPagerAdapter;


public class Edit extends FragmentActivity implements ActionBar.TabListener {

    private ViewPager viewPager;
    private ActionBar actionBar;
    private TabsFragmentPagerAdapter tabsAdapter;
    private String[] activities = new String[]{"Information","Work Force","Work Details"};
    ListView listViewEdit;
    InfoAPI sqlcon;
    private MyDatabaseHelper dbHelper;
    private SQLiteDatabase database;
    private SimpleCursorAdapter dataAdapter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.edit);
        viewPager = (ViewPager) findViewById(R.id.viewPager);
        tabsAdapter = new TabsFragmentPagerAdapter(getSupportFragmentManager());
        viewPager.setAdapter(tabsAdapter);
        actionBar = (ActionBarActivity)getApplicationContext().getSupportActionBar();
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        for(int i=0; i<3; i++){
            actionBar.addTab(actionBar.newTab().setText(activities[i]).setTabListener(this));
        }

Error is on this line actionBar = (ActionBarActivity)getApplicationContext().getSupportActionBar();

Error

Error:(48, 63) error: cannot find symbol method getSupportActionBar()
Error:(48, 21) error: incompatible types: ActionBarActivity cannot be converted to ActionBar

解决方案

Let Edit extend AppCompatActivity instead FragmentActivity. AppCompatActivity extends FragmentActivity and adds support for the ActionBar. You can read more here

这篇关于找不到符号法getSupportActionBar()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆