content: package com.android.androidsidebar;
  
  import android.content.res.ColorStateList;
  import android.os.Bundle;
  import android.support.annotation.NonNull;
  import android.support.annotation.Nullable;
  import android.support.design.widget.NavigationView;
  import android.support.v4.widget.DrawerLayout;
  import android.support.v7.app.ActionBarDrawerToggle;
  import android.support.v7.app.AppCompatActivity;
  import android.support.v7.widget.Toolbar;
  import android.view.MenuItem;
  import android.view.View;
  import android.widget.ImageView;
  import android.widget.LinearLayout;
  import android.widget.TextView;
  import android.widget.Toast;
  
  /**
   * ================================================
   * 项    目：AndroidSidebar
   * 作    者：zj
   * 版    本：1.0
   * 创建日期：2019/4/21
   * 描    述：侧边样式一  Android原生风格
   * 修订历史：
   * ================================================
   */
  public class Style1Activity extends AppCompatActivity {
      @Override
      protected void onCreate(@Nullable Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_style1);
  
          Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
          NavigationView navigationview = (NavigationView) findViewById(R.id.navigation_view);
          final DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
  
          setSupportActionBar(toolbar);//将toolbar与ActionBar关联
          ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                  this, drawer, toolbar, 0, 0);
          drawer.setDrawerListener(toggle);//初始化状态
          toggle.syncState();
  
  
          /*---------------------------添加头布局和尾布局-----------------------------*/
          //获取xml头布局view
          View headerView = navigationview.getHeaderView(0);
          //添加头布局的另外一种方式
          //View headview=navigationview.inflateHeaderView(R.layout.navigationview_header);
  
          //寻找头部里面的控件
          ImageView imageView = headerView.findViewById(R.id.iv_head);
          imageView.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Toast.makeText(getApplicationContext(), "点击了头像", Toast.LENGTH_LONG).show();
              }
          });
          navigationview.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
              @Override
              public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
                  return false;
              }
          });
          ColorStateList csl = (ColorStateList) getResources().getColorStateList(R.color.nav_menu_text_color);
          //设置item的条目颜色
          navigationview.setItemTextColor(csl);
          //去掉默认颜色显示原来颜色  设置为null显示本来图片的颜色
          navigationview.setItemIconTintList(csl);
  
          //设置单个消息数量
          LinearLayout llAndroid = (LinearLayout) navigationview.getMenu().findItem(R.id.single_1).getActionView();
          TextView msg= (TextView) llAndroid.findViewById(R.id.msg_bg);
          msg.setText("99+");
  
          //设置条目点击监听
          navigationview.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
              @Override
              public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
                  //安卓
                  Toast.makeText(getApplicationContext(), menuItem.getTitle(), Toast.LENGTH_LONG).show();
                  //设置哪个按钮被选中
  //                menuItem.setChecked(true);
                  //关闭侧边栏
  //                drawer.closeDrawers();
                  return false;
              }
          });
      }
  }
  