Getsupportactionbar() The Method Getsupportactionbar() Is Undefined For The Type Taskactivity. Why?
Solution 1:
Your class needs to extend from ActionBarActivity
, rather than a plain Activity
in order to use the getSupport*()
methods.
Update [2015/04/23]: With the release of Android Support Library 22.1, you should now extend AppCompatActivity.
Also, you no longer have to extend ActionBarActivity
or AppCompatActivity
, as you can now incorporate an AppCompatDelegate
instance in any activity.
Solution 2:
Here is another solution you could have used. It is working in my app.
@OverridepublicvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
android.support.v7.app.ActionBaractionBar=getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
setContentView(R.layout.activity_main)
Then you can get rid of that import for the one line ActionBar use.
Solution 3:
If you are already extending from ActionBarActivity and you are trying to get the action bar from a fragment:
ActionBarmActionBar= (ActionBarActivity)getActivity()).getSupportActionBar();
Solution 4:
Here is the answer of my question. I've asked that again with some remarks. How to add support libraries?
Solution 5:
If you are extending from an AppCompatActivity and are trying to get the ActionBar from the Fragment, you can do this:
ActionBarmActionBar= ((AppCompatActivity) getActivity()).getSupportActionBar();
Post a Comment for "Getsupportactionbar() The Method Getsupportactionbar() Is Undefined For The Type Taskactivity. Why?"