我正在开发一个应用程序,其中包含导航和滑动两者。但是在导航中,我无法在需要点击侦听器的位置编写代码,因此当我点击该导航部件项目时,它会响应。 下面是我的代码:如何在导航项上设置OnClickListiner
private void init_navigator(){
// Navigation Drawer
mDrawerLayout = (DrawerLayout) findViewById(R.id.main_activity_DrawerLayout);
mDrawerLayout.setStatusBarBackgroundColor(getResources().getColor(R.color.primaryDark));
mScrimInsetsFrameLayout = (ScrimInsetsFrameLayout) findViewById(R.id.main_activity_navigation_drawer_rootLayout);
mActionBarDrawerToggle = new ActionBarDrawerToggle
(
this,
mDrawerLayout,
toolbar,
R.string.navigation_drawer_opened,
R.string.navigation_drawer_closed
)
{
@Override
public void onDrawerSlide(View drawerView, float slideOffset)
{
// Disables the burger/arrow animation by default
super.onDrawerSlide(drawerView, 0);
}
};
mDrawerLayout.setDrawerListener(mActionBarDrawerToggle);
if (getSupportActionBar() != null)
{
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
}
mActionBarDrawerToggle.syncState();
// Navigation Drawer layout width
int possibleMinDrawerWidth = UtilsDevice.getScreenWidth(this) -
UtilsMiscellaneous.getThemeAttributeDimensionSize(this, android.R.attr.actionBarSize);
int maxDrawerWidth = getResources().getDimensionPixelSize(R.dimen.navigation_drawer_max_width);
mScrimInsetsFrameLayout.getLayoutParams().width = Math.min(possibleMinDrawerWidth, maxDrawerWidth);
// Set the first item as selected for the first time
getSupportActionBar().setTitle(R.string.toolbar_title_home);
}
}