从appcompat-v7:21.0.1迁移到appcompat-v7:23.1.1 OnPrepareOptionsMenu未被调用,现在我很伤心。
在迁移支持库之前,根本没有问题。然后在2-3个构建/运行之间(如果我添加代码或添加资源)菜单突然消失,没有错误运行时或编译时。我LOG
onPrepareOptionsMenu
调用并且正如预期的那样,它不会被调用。我试着回到21.0.1,但我遇到了更多可怕的问题。总之,我不能回去。
我一直在做的是
建设 - >清洁
它会再次显示我的菜单。
如果这会有所帮助,我会发布我认为相关的内容:
dependencies {
// compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/mqttv3-1.0.0.jar')
compile 'com.github.traex.rippleeffect:library:1.3'
provided 'com.squareup.dagger:dagger-compiler:1.2.2'
compile('de.keyboardsurfer.android.widget:crouton:1.8.5@aar') {
// exclusion is not neccessary, but generally a good idea.
exclude group: 'com.google.android', module: 'support-v4'
}
// Google Activity Recognition
// Google Maps
// Google+'
// Google Account Login
dependencies {
compile('com.mapbox.mapboxsdk:mapbox-android-sdk:0.7.4@aar') {
transitive = true
}
}
testCompile 'org.mockito:mockito-core:1.9.5'
testCompile files('libs/dexmaker-mockito-1.0.jar')
testCompile files('libs/dexmaker-1.0.jar')
testCompile 'junit:junit:4.12'
testCompile('org.robolectric:robolectric:3.0') {
exclude group: 'commons-logging', module: 'commons-logging'
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
}
testCompile 'com.squareup:fest-android:1.0.+'
testCompile 'org.robolectric:shadows-multidex:3.0'
compile('com.crashlytics.sdk.android:crashlytics:2.2.3@aar') {
transitive = true;
}
compile 'com.wdullaer:materialdatetimepicker:1.4.2'
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
compile 'com.andreabaccega:android-form-edittext:1.1.0@aar'
compile 'com.shehabic.droppy:Droppy:0.2.5.1@aar'
compile 'com.andreabaccega:android-form-edittext:1.1.0@aar'
compile 'com.github.gcacace:signature-pad:1.0.1'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:cardview-v7:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.github.anrwatchdog:anrwatchdog:1.1.1'
compile 'com.android.support:multidex:1.0.1'
compile 'com.squareup.picasso:picasso:2.5.0'
compile 'com.jakewharton:butterknife:6.0.0'
compile 'com.google.code.gson:gson:2.5'
compile 'com.github.bumptech.glide:glide:3.5.2'
compile 'de.greenrobot:eventbus:2.4.0'
compile 'com.squareup.dagger:dagger:1.2.2'
compile 'com.romainpiel.shimmer:library:1.3.0@aar'
compile 'com.michaelpardo:activeandroid:3.1.0-SNAPSHOT'
compile 'info.hoang8f:fbutton:1.0.5'
compile 'com.wrapp.floatlabelededittext:library:0.0.6'
compile 'com.jpardogo.materialtabstrip:library:1.0.9'
compile 'com.github.markushi:circlebutton:1.1'
compile 'com.google.android.gms:play-services-location:8.4.0'
compile 'com.google.android.gms:play-services-maps:8.4.0'
compile 'com.google.android.gms:play-services-plus:8.4.0'
compile 'com.google.android.gms:play-services-identity:8.4.0'
compile 'com.sothree.slidinguppanel:library:3.2.0'
compile 'com.daimajia.swipelayout:library:1.1.9@aar'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.daimajia.easing:library:1.0.0@aar'
compile 'com.daimajia.androidanimations:library:1.1.2@aar'
compile 'com.roomorama:caldroid:1.1.8'
compile 'joda-time:joda-time:2.3'
compile 'com.github.bmelnychuk:atv:1.2.7'
// compile 'org.apache.commons:commons-lang3:3.0'
// compile('com.github.afollestad.material-dialogs:core:0.8.5.+@aar') {
// transitive = true
// }
// compile('com.github.afollestad.material-dialogs:commons:0.8.5.+@aar') {
// transitive = true
// }
compile 'com.github.PhilJay:MPAndroidChart:v2.1.0'
compile 'com.android.support:design:23.1.1'
compile 'com.github.machinarius:preferencefragment:0.1.1'
compile 'com.readystatesoftware.systembartint:systembartint:1.0.3'
compile 'de.hdodenhof:circleimageview:2.0.0'
compile 'com.amazonaws:aws-android-sdk-core:2.+'
compile 'com.amazonaws:aws-android-sdk-s3:2.+'
compile project(':commons')
compile project(':core')
}
我的MainMenu
延伸至AppCompatActivity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// omitted some butterknife injections
if(mToolbar != null ){
setSupportActionBar(mToolbar);
}
mDrawerToggler = new ActionBarDrawerToggle(this ,mDrawer , mToolbar , R.string.drawer_open , R.string.drawer_close ){
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
invalidateOptionsMenu();
}
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
invalidateOptionsMenu();
}
};
mDrawer.setDrawerListener(mDrawerToggler);
}
@Override
protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
final int currentIndex = savedInstanceState.getInt(Constants.CURRENT_POSITION);
selectItem(currentIndex);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt(Constants.CURRENT_POSITION, mListView.getSelectedItemPosition());
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
boolean drawerOpen = mDrawer.isDrawerOpen(mLeftDrawer);
hideMenuItems(menu, !drawerOpen);
Log.w(TAG , "onPrepareOptionsMenu(Menu menu)" );
return super.onPrepareOptionsMenu(menu);
}
private void hideMenuItems(Menu menu, boolean visible){
for(int i = 0; i < menu.size(); i++){
menu.getItem(i).setVisible(visible);
}
}
private void selectItem(int position){
final ActionBar actionBar = getSupportActionBar();
Fragment frag = null;
// omitted some fragment selection process
if(frag != null){
getSupportFragmentManager().beginTransaction()
.replace(R.id.content_frame, frag)
//.setTransition(FragmentTransaction.TRANSIT_ENTER_MASK)
// commitAllowingStateLoss() instead of commit()
// this is a known bug on API > 11
// http://stackoverflow.com/a/10261449/3974048
.commitAllowingStateLoss();
}
if( position != Constants.A_LOGOUT || position != Constants.S_LOGOUT ) {
mListView.setItemChecked(position, true);
}
mDrawer.closeDrawer(mLeftDrawer);
mCurrentPosition = position;
}
谷歌中的
我目前正在使用gradle 2.0.0.alhpa6。来自金丝雀的最新android工作室。