Using actionbarsherlock with android-support-v4 (Version 23)

折月煮酒 提交于 2019-12-12 08:15:48

问题


I'm developing an app with actionbarsherlock and the ABS project is currently using android-support-v4 library (Version 18). Now I want to extend my project to support Android 6.0 and in order to use some of the methods like

ContextCompat.checkSelfPermission(thisActivity, Manifest.permission.WRITE_CALENDAR)

or

ActivityCompat.shouldShowRequestPermissionRationale(thisActivity, Manifest.permission.READ_CONTACTS)

I require support library version 23. But ABS project is not compatible with this latest library and gives error like mAdded cannot be resolved or is not a field in Watson.java

Also, please don't suggest me to use AppCompatActivity instead of ABS as I tried it but getting stuck in a web of other mess as my project is quite big.


回答1:


I'm facing the same problem. Here's my solution:

Clone ActionBarSherlock

No instance field mFragments of type Landroid/support/v4/app/FragmentManagerImpl;

// android.support.v4.app.FragmentActivity

// com.android.support:support-v4:22.+
final FragmentManagerImpl mFragments = new FragmentManagerImpl();

// com.android.support:support-v4:23.+
final FragmentController mFragments = FragmentController.createController(new HostCallbacks());

// android.support.v4.app.FragmentManager.FragmentManagerImpl
ArrayList<Fragment> mAdded;

So we need to get instance of FragmentManagerImpl to access mAdded field

// android.support.v4.app.FragmentActivity
public FragmentManager getSupportFragmentManager() {
    return mFragments.getSupportFragmentManager();
}

// android.support.v4.app.FragmentController
public FragmentManager getSupportFragmentManager() {
    return mHost.getFragmentManagerImpl();
}

Add the following method to the android.support.v4.app.Watson class

@Nullable
private List<Fragment> getAddedFragments() {
    return ((FragmentManagerImpl) getSupportFragmentManager()).mAdded;
}

Add the following code to onCreatePanelMenu, onPreparePanel and onMenuItemSelected methods and replace mFragments.mAdded with fragments

List<Fragment> fragments = getAddedFragments();

FloatMath

Historically these methods were faster than the equivalent double-based {java.lang.Math} methods. On versions of Android with a JIT they became slower and have since been re-implemented to wrap calls to {java.lang.Math}. {java.lang.Math} should be used in preference.

All methods were removed from the public API in version 23.

@deprecated Use {java.lang.Math} instead.

Replace all of occurrences of FloatMath with Math in com.actionbarsherlock.internal.nineoldandroids.view.animation.AnimatorProxy



来源:https://stackoverflow.com/questions/35473639/using-actionbarsherlock-with-android-support-v4-version-23

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!