Android Studio: ActionBar.TabListener does not wor

2019-02-27 21:32发布

I am trying to upgrade some code from FragmentActivity to AppCompatActivity and ActionBar to android.support.v7.app.ActionBar due to deprecation. I've spent a few hours trying to fix this, but I am sure someone with more experience might be able to solve this very quickly.

So my class looks like this now:

import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
//...many other imports here
public class MyClass extends AppCompatActivity implements ActionBar.TabListener{

@Override
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
}
//other code here...
}

My problem is that I am getting an error because Android Studio does not recognize the onTabSelected method signature in the superclass. Changing the tab paramenter to simply "Tab tab" instead of "ActionBar.Tab tab" doesn't help either.

Does anybody have any ideas?

1条回答
可以哭但决不认输i
2楼-- · 2019-02-27 22:24

Like i said, it is deprecated.

See: http://developer.android.com/intl/en/reference/android/support/v7/app/ActionBar.TabListener.html

This interface is deprecated. Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patterns instead.

And about your problem:

Action bar tabs can be replaced by:

Check this link: ActionBarActivity and ActionBar.TabListener is deprecated inside Android Tab Fragment ( Eclipse ApI 22 )

查看更多
登录 后发表回答