我为我的应用创建了导航抽屉,并且工作正常。但是,当我将主活动扩展到类以获取导航抽屉时,未调用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);
答案 0 :(得分:0)
我认为您需要使用您的主要活动new ActionBarDrawerToggle
初始化this
,而不是NavigationDrawerFragment.this
。Answer is already available on stack, still I am repeating:
。