导航抽屉ondrawerOpen和Close未被调用

时间:2015-09-25 04:54:00

标签: android navigation-drawer

我为我的应用创建了导航抽屉,并且工作正常。但是,当我将主活动扩展到类以获取导航抽屉时,未调用onDrawerOpen和onDrawerClose。

这是我需要抽屉的活动

@Override
public void  onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.about_us);
    LayoutInflater inflater = (LayoutInflater) this
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View contentView = inflater.inflate(R.layout.about_us, null, false);
    mDrawerLayout.addView(contentView, 0);
}

这是MainActivity

mDrawerToggle = new ActionBarDrawerToggle(NavigationDrawerFragment.this, mDrawerLayout,
            R.string.navigation_drawer_open,  /* "open drawer" description for accessibility */
            R.string.navigation_drawer_close
    ) {
        @Override
        public void onDrawerClosed(View view) {
            System.out.println("Happy developer");
            super.onDrawerClosed(view);
            //invalidateOptionsMenu();
        }
        @Override
        public void onDrawerOpened(View drawerView) {
            System.out.println("Happy Android");
            super.onDrawerOpened(drawerView);
            //invalidateOptionsMenu();
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);

1 个答案:

答案 0 :(得分:0)

我认为您需要使用您的主要活动new ActionBarDrawerToggle初始化this,而不是NavigationDrawerFragment.thisAnswer is already available on stack, still I am repeating: