Java 类android.support.design.widget.NavigationView 实例源码

项目:gamecollection    文件:Hub.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setDefaultValuesOfSettingsFirstTime();

    setContentView(R.layout.activity_hub);
    setupActionBar();

    drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    navigationView = (NavigationView) findViewById(R.id.nav_view);

    setupNavigationView();

    if (savedInstanceState == null) {
        currentTag = tagHub;
        loadHomeFragment();
    } else {
        setToolbarTitle();
    }
}
项目:Hello-KUET    文件:MainActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

}
项目:GitHub    文件:MainActivity.java   
private void initViews() {

        toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this,
                drawer,
                toolbar,
                R.string.navigation_drawer_open,
                R.string.navigation_drawer_close);
        drawer.setDrawerListener(toggle);
        toggle.syncState();

        navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);

    }
项目:GitHub    文件:TasksActivity.java   
private void setupDrawerContent(NavigationView navigationView) {
    navigationView.setNavigationItemSelectedListener(
            menuItem -> {
                switch (menuItem.getItemId()) {
                    case R.id.list_navigation_menu_item:
                        // Do nothing, we're already on that screen
                        break;
                    case R.id.statistics_navigation_menu_item:
                        Intent intent =
                                new Intent(TasksActivity.this, StatisticsActivity.class);
                        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                                | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                        startActivity(intent);
                        break;
                    default:
                        break;
                }
                // Close the navigation drawer when an item is selected.
                menuItem.setChecked(true);
                mDrawerLayout.closeDrawers();
                return true;
            });
}
项目:GitHub    文件:StatisticsActivity.java   
private void setupDrawerContent(NavigationView navigationView) {
    navigationView.setNavigationItemSelectedListener(
            menuItem -> {
                switch (menuItem.getItemId()) {
                    case R.id.list_navigation_menu_item:
                        Intent intent =
                                new Intent(StatisticsActivity.this, TasksActivity.class);
                        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                                | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                        startActivity(intent);
                        break;
                    case R.id.statistics_navigation_menu_item:
                        // Do nothing, we're already on that screen
                        break;
                    default:
                        break;
                }
                // Close the navigation drawer when an item is selected.
                menuItem.setChecked(true);
                mDrawerLayout.closeDrawers();
                return true;
            });
}
项目:GitHub    文件:MainActivity.java   
private void initializeDrawer() {
    mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, mDrawer, mToolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    mDrawer.addDrawerListener(toggle);
    toggle.syncState();

    mNavigationView = (NavigationView) findViewById(R.id.nav_view);
    mNavigationView.setNavigationItemSelectedListener(this);

    // Version
    TextView appVersion = (TextView) mNavigationView.getHeaderView(0).findViewById(R.id.app_version);
    appVersion.setText(getString(R.string.about_version,
            Utils.getVersionName(this),
            Integer.toString(Utils.getVersionCode(this))));
}
项目:GitHub    文件:MainActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  setSupportActionBar(toolbar);

  DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
  ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
      this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
  drawer.setDrawerListener(toggle);
  toggle.syncState();

  NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
  navigationView.setNavigationItemSelectedListener(this);

  if (savedInstanceState == null) {
    int selectedItem = PreferenceManager.getDefaultSharedPreferences(this).getInt(
        KEY_SELECTED_NAVDRAWER_ITEM_ID,
        INITIAL_NAVDRAWER_ITEM_ID);
    handleNavigationItemClick(selectedItem);
    navigationView.setCheckedItem(selectedItem);
  }
}
项目:iSPY    文件:Dashboard.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_dashboard);


        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    if(ActivityCompat.checkSelfPermission(this,android.Manifest.permission.ACCESS_FINE_LOCATION)!= PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this,android.Manifest.permission.ACCESS_COARSE_LOCATION)!=PackageManager.PERMISSION_GRANTED ) {
        checkLocationPermission();
        return;
    }
}
项目:Matrix-Calculator-for-Android    文件:CloneFragment.java   
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    if (((GlobalValues) getActivity().getApplication()).CanCreateVariable()) {
        Matrix m = ((GlobalValues) getActivity().getApplication()).GetCompleteList().get(position);
        Matrix clone;
        clone = m.ExactClone("Copy_" + m.GetName());
        ((GlobalValues) getActivity().getApplication()).GetCompleteList().add(clone);
        ((GlobalValues) getActivity().getApplication()).matrixAdapter.notifyDataSetChanged();
        Toast.makeText(getContext(), "Saved as Copy_" + m.GetName(), Toast.LENGTH_SHORT).show();
        NavigationView view = (NavigationView) getActivity().findViewById(R.id.nav_view);
        view.setCheckedItem(R.id.Home);
        FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.MainContent, new MainActivityFragmentList());
        transaction.commit();
        ((MainActivity) getActivity()).SetMainActivity(true, getString(R.string.app_name), getString(R.string.MainSubtitle));
    } else {
        if (!((GlobalValues) getActivity().getApplication()).AdLoaded)
            Toast.makeText(getContext(), R.string.ToAddMoreTurnData, Toast.LENGTH_SHORT).show();
        else
            Toast.makeText(getContext(), R.string.LimitExceeds, Toast.LENGTH_SHORT).show();
    }


}
项目:statelayout    文件:MainActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main2);

    setTitle("Default");

    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    DrawerLayout drawer = findViewById(R.id.drawer_layout);

    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this,
            drawer, toolbar,
            R.string.navigation_drawer_open,
            R.string.navigation_drawer_close);

    drawer.addDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
}
项目:cat-is-a-dog    文件:BaseDrawerActivity.java   
/**
 * Logic for toolbar
 */
protected void drawToolbar() {
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    View header = navigationView.getHeaderView(0);
    TextView name = (TextView) header.findViewById(R.id.navBarUserName);

    //Get username info to display on header
    User currUser = CurrentUser.getInstance();
    name.setText(currUser.getDisplayName());

    ImageView photoView = (ImageView) header.findViewById(R.id.navBarUserImage);
    photoView.setTag(currUser.getPhotoUrl());
    new DownloadImageTask().execute(photoView);

}
项目:FastAndroid    文件:DrawerActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_drawer);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
}
项目:SmackStudy    文件:MainActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
}
项目:AstronomyTourPadova    文件:ReceiverActivity.java   
@Override
protected void onCreate(Bundle savedInstanceStatus) {
    Log.d(TAG, "onCreate()");
    super.onCreate(savedInstanceStatus);

    // Service connection
    atReceiver = new AtReceiver();

    // Drawer Layout
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

    // Left Menu
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    if (navigationView != null) {
        setupDrawerContent(navigationView);
    }
    setNavigationViewListner();
}
项目:iSPY    文件:Notepad1.java   
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_notepad1);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
    /*    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Save("Note1.txt");
            }
        });
*/
        EditText1 = (EditText) findViewById(R.id.EditText1);
        EditText1.setText(Open("Note1.txt"));
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.setDrawerListener(toggle);
        toggle.syncState();

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);
    }
项目:Trackr    文件:MainMenuActivity.java   
public void loadProfileInformation() {


        NavigationView navigationView = (NavigationView) findViewById(R.id.navigationView);
        View header = navigationView.getHeaderView(0);
        textView_profile_id = (TextView) header.findViewById(R.id.textViewProfileId);
        textView_profile_name = (TextView) header.findViewById(R.id.textViewProfileName);
        textView_profile_phone = (TextView) header.findViewById(R.id.textViewProfilePhone);

        Gson gson = new Gson();
        String json = sharedPreferencesProfileInformation.getString("currentUser", "");
        currentUser = gson.fromJson(json, User.class);

        textView_profile_id.setText(String.valueOf(currentUser.getId()));
        textView_profile_name.setText(currentUser.getFname() + " " + currentUser.getLname());
        textView_profile_phone.setText(currentUser.getPhone());

    }
项目:ingetin    文件:MainActivityOld.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    activityTitles = getResources().getStringArray(R.array.nav_item_activity_titles);

    setSupportActionBar(toolbar);

    getSupportActionBar().setTitle(activityTitles[0]);

    final DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    mFragmentManager = getSupportFragmentManager();
    mFragmentTransaction = mFragmentManager.beginTransaction();
    mFragmentTransaction.replace(R.id.containerView,new TabFragment()).commit();

}
项目:couch-potatoes    文件:ChatRoomActivity.java   
private void setSideBarDrawer( DrawerLayout mDrawer, NavigationView navView,
                               Toolbar toolbar, DBHelper helper) {
    // enables toggle button on toolbar to open the sidebar
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, mDrawer, toolbar, R.string.navigation_drawer_open,
            R.string.navigation_drawer_close);
    mDrawer.addDrawerListener(toggle);
    toggle.syncState();

    // set up side navigation bar layout
    navView.setNavigationItemSelectedListener(this);

    // Want to display icons in original color scheme
    navView.setItemIconTintList(null);

    // highlight the current location
    navView.setCheckedItem(R.id.nav_matches);

    // sets up TextViews in sidebar to display the user's name and email
    sidebarUserName = (android.widget.TextView) navView.getHeaderView(0)
            .findViewById(R.id.sidebar_username);
    sidebarUserEmail = (android.widget.TextView) navView.getHeaderView(0)
            .findViewById(R.id.sidebar_user_email);
    setSideBarText( sidebarUserName, sidebarUserEmail, helper );
}
项目:TeamCSSS-Enactus    文件:homePage.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home_page);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
}
项目:Book-Shelf    文件:HomeActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
    ButterKnife.bind(this);

    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayShowTitleEnabled(false);

    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
}
项目:1617PROJ1Bloeddonatie-app    文件:SideBar.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_side_bar);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                .setAction("Action", null).show();
        }
    });

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
        this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
}
项目:VerticalWebView    文件:MainActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
}
项目:Sistema-de-Comercializacion-Negocios-Jhordan    文件:Usuarios.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_usuarios_navigation_drawer);
    this.setTitle(R.string.nav_usuarios);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_usuarios);
    setSupportActionBar(toolbar);

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.usuarios_drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.usuarios_nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    navigationView.setCheckedItem(R.id.nav_usuarios);
}
项目:android-app-aam    文件:MainActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);


    FragmentTransaction ft = getFragmentManager().beginTransaction();
    Fragment fragment = new FragmentFeed();
    ft.addToBackStack(null);
    ft.replace(R.id.content_main, fragment).commit();



    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });


    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);


}
项目:Automata    文件:Main.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);



    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    if (savedInstanceState == null) {
        // on first time to display view for first navigation item based on the number
        navigationView.getMenu().getItem(0).setChecked(true);
        onNavigationItemSelected(navigationView.getMenu().getItem(0));
    }

}
项目:LianXiZhihu    文件:MainActivity.java   
private void initViews() {

        toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this,
                drawer,
                toolbar,
                R.string.navigation_drawer_open,
                R.string.navigation_drawer_close);
        drawer.setDrawerListener(toggle);
        toggle.syncState();

        navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);

    }
项目:shareNote    文件:MainActivity.java   
@Override
protected void onListener() {
    super.onListener();
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            int id = item.getItemId();
            if (id == R.id.notebookMenuId) {
                startActivity(new Intent(getApplication(), NoteActivity.class));
            }
            if (id == R.id.recycleMenuId) {
                startActivity(new Intent(getApplication(), RecycleActivity.class));
            }
            if (id == R.id.settingMenuId) {
                startActivity(new Intent(getApplication(), SettingsActivity.class));
            }
            return false;
        }
    });
}
项目:Sistema-de-Comercializacion-Negocios-Jhordan    文件:Reportes.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_reportes_navigation_drawer);
    this.setTitle(R.string.nav_reportes);

    /*menu*/
    BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
    navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_reportes);
    setSupportActionBar(toolbar);

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.reportes_drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.reportes_nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    navigationView.setCheckedItem(R.id.nav_reportes);
}
项目:DAPNETApp    文件:MainActivity.java   
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    Menu nv = navigationView.getMenu();
    MenuItem mloginstatus = nv.findItem(R.id.nav_loginstatus);
    SharedPreferences sharedPref = getSharedPreferences("sharedPref", Context.MODE_PRIVATE);
    loggedIn = sharedPref.getBoolean("isLoggedIn", false);
    mServer = sharedPref.getString("server", null);

    if (loggedIn) {
        mloginstatus.setTitle(R.string.nav_logout);
        Log.i(TAG, "User is logged in!");
    } else {
        mloginstatus.setTitle(R.string.nav_login);
        Log.i(TAG, "User is not logged in!");
    }
    if (mServer != null) {
        setVersion(mServer);
    } else {
        setVersion("http://hampager.de:8080");
        //if mServer == null
        // setVersion("http://dapnet.db0sda.ampr.org:8080")
    }

    return true;
}
项目:CommonFramework    文件:MainActivity.java   
private void setDrawerLayout() {
    mDrawerLayout.setStatusBarBackground(R.color.colorPrimaryDark);
    NavigationView navigationView = (NavigationView) findViewById(R.id.main_navView);
    if(navigationView != null) {
        setupDrawerContent(navigationView);
    }
}
项目:Bluetooth_BLE    文件:MainActivity.java   
private void initView() {
    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mNavView = (NavigationView) findViewById(R.id.nav_view);

    setSupportActionBar(mToolbar);

    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.open, R.string.close);
    mDrawerLayout.setDrawerListener(toggle);
    toggle.syncState();

    mNavView.setNavigationItemSelectedListener(this);
}
项目:GitHub    文件:MainActivity.java   
void setupNavMenu() {
    View headerLayout = mNavigationView.getHeaderView(0);
    mProfileImageView = (RoundedImageView) headerLayout.findViewById(R.id.iv_profile_pic);
    mNameTextView = (TextView) headerLayout.findViewById(R.id.tv_name);
    mEmailTextView = (TextView) headerLayout.findViewById(R.id.tv_email);

    mNavigationView.setNavigationItemSelectedListener(
            new NavigationView.OnNavigationItemSelectedListener() {
                @Override
                public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                    mDrawer.closeDrawer(GravityCompat.START);
                    switch (item.getItemId()) {
                        case R.id.nav_item_about:
                            mPresenter.onDrawerOptionAboutClick();
                            return true;
                        case R.id.nav_item_rate_us:
                            mPresenter.onDrawerRateUsClick();
                            return true;
                        case R.id.nav_item_feed:
                            mPresenter.onDrawerMyFeedClick();
                            return true;
                        case R.id.nav_item_logout:
                            mPresenter.onDrawerOptionLogoutClick();
                            return true;
                        default:
                            return false;
                    }
                }
            });
}
项目:iNews    文件:MainActivity.java   
private void initViews() {
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer);
    mNavigationView = (NavigationView) findViewById(R.id.navigation);
    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(mToolbar);
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.drawer_open, R.string.drawer_close);
    //绑定toggle与drawer
    mDrawerLayout.addDrawerListener(mDrawerToggle);
    //设置drawer的item点击事件监听器
    setupWithNavigationView(mNavigationView);
    FragmentUtil.addFragment(getSupportFragmentManager(), new NewsTabAndPagerFragment());
    getSupportActionBar().setTitle(R.string.news);
}
项目:GitHub    文件:StatisticsActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.statistics_act);

    // Set up the toolbar.
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar ab = getSupportActionBar();
    ab.setTitle(R.string.statistics_title);
    ab.setHomeAsUpIndicator(R.drawable.ic_menu);
    ab.setDisplayHomeAsUpEnabled(true);

    // Set up the navigation drawer.
    mDrawerLayout = findViewById(R.id.drawer_layout);
    mDrawerLayout.setStatusBarBackground(R.color.colorPrimaryDark);
    NavigationView navigationView = findViewById(R.id.nav_view);
    if (navigationView != null) {
        setupDrawerContent(navigationView);
    }

    StatisticsFragment statisticsFragment = (StatisticsFragment) getSupportFragmentManager()
            .findFragmentById(R.id.contentFrame);
    if (statisticsFragment == null) {
        statisticsFragment = StatisticsFragment.newInstance();
        ActivityUtils.addFragmentToActivity(getSupportFragmentManager(),
                statisticsFragment, R.id.contentFrame);
    }

    new StatisticsPresenter(
            Injection.provideTasksRepository(getApplicationContext()), statisticsFragment,
            Injection.provideSchedulerProvider());
}
项目:Android-skin-support    文件:SkinMaterialNavigationView.java   
public SkinMaterialNavigationView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    mBackgroundTintHelper = new SkinCompatBackgroundHelper(this);
    mBackgroundTintHelper.loadFromAttributes(attrs, 0);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.NavigationView, defStyleAttr,
            R.style.Widget_Design_NavigationView);
    if (a.hasValue(R.styleable.NavigationView_itemIconTint)) {
        mIconTintResId = a.getResourceId(R.styleable.NavigationView_itemIconTint, INVALID_ID);
    } else {
        mDefaultTintResId = SkinCompatThemeUtils.getColorPrimaryResId(context);
    }
    if (a.hasValue(R.styleable.NavigationView_itemTextAppearance)) {
        int textAppearance = a.getResourceId(R.styleable.NavigationView_itemTextAppearance, INVALID_ID);
        if (textAppearance != INVALID_ID) {
            TypedArray ap = context.obtainStyledAttributes(textAppearance, R.styleable.SkinTextAppearance);
            if (ap.hasValue(R.styleable.SkinTextAppearance_android_textColor)) {
                mTextColorResId = ap.getResourceId(R.styleable.SkinTextAppearance_android_textColor, INVALID_ID);
            }
            ap.recycle();
        }
    }
    if (a.hasValue(R.styleable.NavigationView_itemTextColor)) {
        mTextColorResId = a.getResourceId(R.styleable.NavigationView_itemTextColor, INVALID_ID);
    } else {
        mDefaultTintResId = SkinCompatThemeUtils.getColorPrimaryResId(context);
    }
    if (mTextColorResId == INVALID_ID) {
        mTextColorResId = SkinCompatThemeUtils.getTextColorPrimaryResId(context);
    }
    mItemBackgroundResId = a.getResourceId(R.styleable.NavigationView_itemBackground, INVALID_ID);
    a.recycle();
    applyItemIconTintResource();
    applyItemTextColorResource();
    applyItemBackgroundResource();
}
项目:Mingnote    文件:MainActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_app);
    setSupportActionBar(toolbar);
    InitView();
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab_editnote);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(MainActivity.this, NoteEdit.class);
            Bundle bundle = new Bundle();//在活动间传递数据
            bundle.putString("info", "");
            bundle.putInt("enter_state", 0);
            intent.putExtras(bundle);
            startActivity(intent);
        }
    });

    final DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
}
项目:GitHub    文件:BaseDrawerActivity.java   
@Override
protected void setBaseView(@LayoutRes int layoutId) {
    contentView = LayoutInflater.from(this).inflate(R.layout.activity_drawer, null);
    setContentView(contentView);
    rootLayout = (DrawerLayout) findViewById(R.id.root_layout);
    flActivityContainer = (FrameLayout) findViewById(R.id.activity_container);
    flActivityContainer.addView(LayoutInflater.from(this).inflate(layoutId, flActivityContainer, false));
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(mListener);
}
项目:OracionesCatolicas    文件:AbstractFragment.java   
@Override
public void onAttach(Context context) {
    super.onAttach(context);
    if (context instanceof NavigationView.OnNavigationItemSelectedListener) {
        mListener = (NavigationView.OnNavigationItemSelectedListener) context;
    } else {
        throw new RuntimeException(context.toString() + " must implement NavigationView.OnNavigationItemSelectedListener");
    }
}
项目:HustEating    文件:MainActivity.java   
/**
 * 从外部回来的时候检查一次登录状态(防止从注册界面返回导致登录状态不刷新)
 */
@Override
protected void onResume() {
    Log.d("onResume", "onResume");
    updateDrawerHead((NavigationView) findViewById(R.id.nav_view));
    super.onResume();
}
项目:MapaDeIgarassuAdmin    文件:HomeActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.home_activity);

    /*SupportMapFragment ==> Mapa*/
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(map);
    mapFragment.getMapAsync(this);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, 0, 0);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    /*Inflate para o pop-up dos markers(Janela em cima do marker)*/
    this.markerView = getLayoutInflater().inflate(R.layout.marker_view, null);

    invokeAddMarkerMapOther = new InvokeAddMarkerMapOther(this.context);

}