关闭上一个活动后,汉堡图标在后退箭头图标上发生变化

时间:2017-11-15 13:20:41

标签: android navigation-drawer

我正在从应用程序的导航抽屉中打开“关于”页面。它创建一个intent并启动一个新的Activity。在AboutActivity中,我显示了一个后退箭头,当我在MainActivity上关闭此活动时,汉堡图标变为后退箭头图标。

这是MainActivity:

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mDrawerToggle = new ActionBarDrawerToggle(
            this, mDrawer, mToolbar, R.string.drawer_open, R.string.drawer_close) {
        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            LogUtils.d(TAG, "onDrawerOpened() ");

            KeyboardUtils.hideKeyboard(getBaseContext(), drawerView);

            invalidateOptionsMenu();
        }

        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            LogUtils.d(TAG, "onDrawerClosed: " + getTitle());
            invalidateOptionsMenu();
        }
    };
    //calling sync state is necessary or else your hamburger icon wont show up
    mDrawerToggle.setDrawerIndicatorEnabled(true);
    mDrawerToggle.syncState();

    /* res/menu/drawer_menu.xml */
    mNavigationView.setNavigationItemSelectedListener(this);

    setContentView(R.layout.activity_main);
}

@Override
protected void onResume() {
    super.onResume();

    if(getSupportActionBar() != null){
        getSupportActionBar().setDisplayHomeAsUpEnabled(false);
    }
    mDrawerToggle.syncState();
}

这是关于活动:

public class AboutActivity extends AppCompatActivity {

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final String version = getString(R.string.about_version, BuildConfig.VERSION_NAME, String.valueOf(BuildConfig.VERSION_CODE));
    final View aboutPage = new AboutPage(this)
            .isRTL(false)
            .setDescription(version)
            .addGroup("Connect with us")
            .addEmail("log@lunni.fi")
            .addPlayStore("fi.lunni.mobileadvisor")
            .addYoutube("UCubK_NmfkAGPzo5UfiStsVQ")
            .addWebsite("https://lunni.fi/")
            .create();

    final ImageView image = (ImageView) aboutPage.findViewById(mehdi.sakout.aboutpage.R.id.image);
    image.setImageDrawable(ImgUtils.changeColor(this, R.drawable.lunni_logo_icon_white, R.color.lunni_blue));
    setContentView(aboutPage);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        // Respond to the action bar's Up/Home button
        case android.R.id.home:
            NavUtils.navigateUpFromSameTask(this);
            return true;
    }
    return super.onOptionsItemSelected(item);
}
}

在Manifest.xml中

    <activity android:name=".ui.activities.AboutActivity">
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value=".ui.activities.MainActivity" />
    </activity>

1 个答案:

答案 0 :(得分:0)

onResume()

中删除此行
getSupportActionBar().setDisplayHomeAsUpEnabled(false);