本文介绍了getSupportActionBar()的方法getSupportActionBar()是未定义的类型TaskActivity。为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建议从ActionBarActivity致以Activity类

下面是previous code:

 进口android.support.v7.app.ActionBar;
进口android.support.v7.app.ActionBarActivity;

公共类MainActivity延伸活动{

@覆盖
保护无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.activity_main);
}
 

我写了新的应用程序,并遵循建议。

 进口android.os.Bundle;
    进口android.support.v7.app.ActionBar;
    进口android.support.v7.app.ActionBarActivity;

    公共类MainActivity扩展ActionBarActivity {

          @覆盖
          公共无效的onCreate(包savedInstanceState){
            super.onCreate(savedInstanceState);
            动作条动作条= getSupportActionBar();
            actionBar.setDisplayHomeAsUpEnabled(真正的);
            的setContentView(R.layout.activity_main);
          }

          @覆盖
          公共布尔onCreateOptionsMenu(功能菜单){
            。getMenuInflater()膨胀(R.menu.main,菜单);
            返回true;
          }
        }
 

如果我用,而不是活动ACtionBarActivity,我得到以下错误的电话,当我尝试运行它:

解决方案

下面是我的问题的答案。我问过一遍了一些言论。如何添加支持库?

I was recommended to extend my Activity class from ActionBarActivity

Here is the previous code:

import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;

public class MainActivity extends Activity  {

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

I wrote new application and followed advice.

import android.os.Bundle;
    import android.support.v7.app.ActionBar;
    import android.support.v7.app.ActionBarActivity;

    public class MainActivity extends ActionBarActivity {

          @Override
          public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            ActionBar actionBar =getSupportActionBar();
            actionBar.setDisplayHomeAsUpEnabled(true);
            setContentView(R.layout.activity_main);
          }

          @Override
          public boolean onCreateOptionsMenu(Menu menu) {
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
          }
        }

If I use ACtionBarActivity instead of Activity, I get the following error on the phone, when I try to run it:

解决方案

Here is the answer of my question.I've asked that again with some remarks.How to add support libraries?

这篇关于getSupportActionBar()的方法getSupportActionBar()是未定义的类型TaskActivity。为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-18 08:15