我的向上导航无效。 “返回” - 箭头显示在我的WinnerListActivity
中,但点击后它不会返回到父项MainActivity
,而是打开我的导航抽屉。没有触发Log() - 方法。我很确定它与我的ActionBarDrawerToggle
有关,但我无法弄清楚出了什么问题。有什么遗漏吗?
AndroidManifest:
<activity android:name=".activity.MainActivity" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".activity.WinnerListActivity" android:screenOrientation="portrait" android:parentActivityName=".activity.MainActivity" />
WinnerListActivity:
public class WinnerListActivity extends NavigationActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_winner_list);
super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Log.i(TAG, "item: " + item.getItemId());
return super.onOptionsItemSelected(item);
}
}
NavigationActivity:
public class NavigationActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
toggle = new ActionBarDrawerToggle(
this, drawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawerLayout.addDrawerListener(toggle);
toggle.syncState();
toggle.setToolbarNavigationClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.i(TAG, "setToolbarNavigationClickListener");
}
});
}
}
activity_winner_list.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout>
<android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.AppBarLayout>
<android.support.design.widget.CollapsingToolbarLayout>
<include layout="@layout/include_toolbar_cover" />
<android.support.v7.widget.Toolbar />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView>
<android.support.v7.widget.RecyclerView />
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView />
</android.support.v4.widget.DrawerLayout>