我正在開發一個應用程序,其中包含導航和滑動兩者。但是在導航中,我無法在需要點擊偵聽器的位置編寫代碼,因此當我點擊該導航部件項目時,它會響應。 下面是我的代碼:如何在導航項上設置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);
}
}