android.support.design.widget.NavigationView.inflateHeaderView()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(9.3k)|赞(0)|评价(0)|浏览(170)

本文整理了Java中android.support.design.widget.NavigationView.inflateHeaderView()方法的一些代码示例,展示了NavigationView.inflateHeaderView()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。NavigationView.inflateHeaderView()方法的具体详情如下:
包路径:android.support.design.widget.NavigationView
类名称:NavigationView
方法名:inflateHeaderView

暂无

代码示例

代码示例来源:origin: naman14/Timber

View header = navigationView.inflateHeaderView(R.layout.nav_header);

代码示例来源:origin: chenyangcun/MaterialDesignExample

private void setUpProfileImage() {
  View headerView=  mNavigationView.inflateHeaderView(R.layout.navigation_header);
  View profileView = headerView.findViewById(R.id.profile_image);
  if (profileView != null) {
    profileView.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        switchToBlog();
        mDrawerLayout.closeDrawers();
        mNavigationView.getMenu().getItem(1).setChecked(true);
      }
    });
  }
}

代码示例来源:origin: eneim/toro

navView.inflateHeaderView(R.layout.widget_space_4dp);
View header1 = navView.inflateHeaderView(R.layout.widget_hom_nav_header_1);
TextView header1Text = header1.findViewById(R.id.text_content);
header1Text.setText(getString(R.string.lib_info_version, BuildConfig.VERSION_NAME));
navView.inflateHeaderView(R.layout.widget_hom_nav_header_2);
navView.getHeaderView(3).<TextView>findViewById(R.id.text_content).setText(
  Html.fromHtml(getString(R.string.lib_info_license)));

代码示例来源:origin: HotBitmapGG/MoeQuest

private void setNavigationView() {
 mNavigationView.setNavigationItemSelectedListener(this);
 View headerView = mNavigationView.inflateHeaderView(R.layout.nav_header_main);
 CircleImageView mCircleImageView = (CircleImageView) headerView.findViewById(
   R.id.nav_head_avatar);
 int randomNum = random.nextInt(avatars.length);
 mCircleImageView.setImageResource(avatars[randomNum]);
}

代码示例来源:origin: andyiac/githot

private void initLoginView(NavigationView navigationView) {
  View headerView = navigationView.inflateHeaderView(R.layout.nav_header);
  imageAvatar = (CircleImageView) headerView.findViewById(R.id.id_nav_header_avatar);
  tvName = (TextView) headerView.findViewById(R.id.id_nav_header_uname);
  tvHtmlUrl = (TextView) headerView.findViewById(R.id.id_nav_header_giturl);
  tvName.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
      openLoginInBrowser();
    }
  });
  imageAvatar.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
      openLoginInBrowser();
    }
  });
}

代码示例来源:origin: WuXiaolong/DesignSupportLibrarySample

private void initNavigationViewHeader() {
  navigationView = (NavigationView) findViewById(R.id.navigation);
  //设置头像,布局app:headerLayout="@layout/drawer_header"所指定的头布局
  View view = navigationView.inflateHeaderView(R.layout.drawer_header);
  TextView userName = (TextView) view.findViewById(R.id.userName);
  userName.setText(R.string.author);
  //View mNavigationViewHeader = View.inflate(MainActivity.this, R.layout.drawer_header, null);
  //navigationView.addHeaderView(mNavigationViewHeader);//此方法在魅族note 1,头像显示不全
  //菜单点击事件
  navigationView.setNavigationItemSelectedListener(new NavigationItemSelected());
}

代码示例来源:origin: NativeMonkey/ofo

private void initDrawerLayout() {
  navView.inflateHeaderView(R.layout.nav_header_main);
  View headerView = navView.getHeaderView(0);
  RelativeLayout rl_header_bg = (RelativeLayout) headerView.findViewById(R.id.rl_header_bg);
  LinearLayout ll_nav_trip = (LinearLayout) headerView.findViewById(R.id.ll_nav_trip);
  LinearLayout ll_nav_money = (LinearLayout) headerView.findViewById(R.id.ll_nav_money);
  LinearLayout ll_nav_message = (LinearLayout) headerView.findViewById(R.id.ll_nav_message);
  LinearLayout ll_nav_guide = (LinearLayout) headerView.findViewById(R.id.ll_nav_guide);
  LinearLayout ll_nav_setting = (LinearLayout) headerView.findViewById(R.id.ll_nav_setting);
  rl_header_bg.setOnClickListener(this);
  ll_nav_trip.setOnClickListener(this);
  ll_nav_money.setOnClickListener(this);
  ll_nav_message.setOnClickListener(this);
  ll_nav_guide.setOnClickListener(this);
  ll_nav_setting.setOnClickListener(this);
  llTitleMenu.setOnClickListener(this);
}

代码示例来源:origin: canqihe/TmallSale

@Override
protected void initView() {
  setContentView(R.layout.activity_main);
  MobclickAgent.setScenarioType(this, MobclickAgent.EScenarioType.E_UM_NORMAL);
  ButterKnife.bind(this);
  headView = navigationView.inflateHeaderView(R.layout.nav_header_main);
  drawerHeader = (LinearLayout) headView.findViewById(R.id.drawer_header);
}

代码示例来源:origin: zzkong/BaseProject

@Override
protected void initEventAndData() {
  StatusBarUtil.setColorForDrawerLayout(this, mDrawerLayout, ResourceUtil.getThemeColor(this), 0);
  ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
      this, mDrawerLayout, mToolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
  mDrawerLayout.setDrawerListener(toggle);
  toggle.syncState();
  View headerView = mNavView.inflateHeaderView(R.layout.nav_header_main);
  mHeadBgImg = (ImageView) headerView.findViewById(R.id.head_image);
  mAvatorImg = (ImageView) headerView.findViewById(R.id.imageView);
  EventHelper.click(this, mFab, mAvatorImg);
  EventHelper.setNavigationItemSelected(this, mNavView);
  getBitmap();
  setNewRootFragment(R.id.nav_gank);
}

代码示例来源:origin: dabutaizha/juzimi

@Override
protected void initView() {
  setSupportActionBar(mToolbar);
  mToolbar.setNavigationIcon(R.drawable.nav_icon);
  mToolbar.setTitle(R.string.app_name);
  mToolbar.setTitleTextColor(ContextCompat.getColor(this, R.color.colorAccent));
  mTabAdapter = new TabAdapter(this, getSupportFragmentManager());
  mViewPager.setAdapter(mTabAdapter);
  mTabLayout.setupWithViewPager(mViewPager);
  View navHeaderView = mNavigationView.inflateHeaderView(R.layout.nav_header_main);
  mAccountInfo = navHeaderView.findViewById(R.id.app_collect_info);
  mAddSentences = navHeaderView.findViewById(R.id.app_add_personal_sentences);
  mNavHeaderBackground = navHeaderView.findViewById(R.id.app_nav_header_bg);
  mAddSentences.post(() -> {
    if (Constant.INPUT_SENTENCE_PREMISSION) {
      mAddSentences.setText(getString(R.string.add_personal_sentences));
    } else {
      //do anything
    }
  });
}

代码示例来源:origin: opengit/AndroidNewWidgetsDemo

private void configViews() {
 // 设置显示Toolbar
 setSupportActionBar(mToolbar);
 // 设置Drawerlayout开关指示器,即Toolbar最左边的那个icon
 ActionBarDrawerToggle mActionBarDrawerToggle =
   new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.open, R.string.close);
 mActionBarDrawerToggle.syncState();
 mDrawerLayout.setDrawerListener(mActionBarDrawerToggle);
 //给NavigationView填充顶部区域,也可在xml中使用app:headerLayout="@layout/header_nav"来设置
 mNavigationView.inflateHeaderView(R.layout.header_nav);
 //给NavigationView填充Menu菜单,也可在xml中使用app:menu="@menu/menu_nav"来设置
 mNavigationView.inflateMenu(R.menu.menu_nav);
 // 自己写的方法,设置NavigationView中menu的item被选中后要执行的操作
 onNavgationViewMenuItemSelected(mNavigationView);
 // 初始化ViewPager的适配器,并设置给它
 mViewPagerAdapter = new MyViewPagerAdapter(getSupportFragmentManager(), mTitles, mFragments);
 mViewPager.setAdapter(mViewPagerAdapter);
 // 设置ViewPager最大缓存的页面个数
 mViewPager.setOffscreenPageLimit(5);
 // 给ViewPager添加页面动态监听器(为了让Toolbar中的Title可以变化相应的Tab的标题)
 mViewPager.addOnPageChangeListener(this);
 mTabLayout.setTabMode(MODE_SCROLLABLE);
 // 将TabLayout和ViewPager进行关联,让两者联动起来
 mTabLayout.setupWithViewPager(mViewPager);
 // 设置Tablayout的Tab显示ViewPager的适配器中的getPageTitle函数获取到的标题
 mTabLayout.setTabsFromPagerAdapter(mViewPagerAdapter);
 // 设置FloatingActionButton的点击事件
 mFloatingActionButton.setOnClickListener(this);
}

代码示例来源:origin: werbhelius/Werb

private void initHeadView(){
  View headerView = mNavigationView.inflateHeaderView(R.layout.left_draw_header);
  userBackGround = (ImageView) headerView.findViewById(R.id.iv_user_bg);
  userIcon = (ClickCircleImageView) headerView.findViewById(R.id.iv_user_icon);
  userName = (TextView) headerView.findViewById(R.id.tv_user_name);
  mNavigationView.setCheckedItem(R.id.home);
  replaceFragment(new HomeFragment());
  mNavigationView.setNavigationItemSelectedListener(item -> {
    switch (item.getItemId()){
      case R.id.home:
        replaceFragment(new HomeFragment());
        break;
      case R.id.find:
        replaceFragment(new FindFragment());
        break;
    }
    item.setChecked(true);
    mDrawerLayout.closeDrawers();
    return true;
  });
}

代码示例来源:origin: flyleft/xmarket

@Override
protected void initViews(Bundle savedInstanceState) {
  setContentView(R.layout.main_activity);
  realm=Realm.getDefaultInstance();
  PollingUtils.startPollingService(this, 5, MessageService.class, MessageService.ACTION);
  unbinder=ButterKnife.bind(this);
  presenter=new MainPresenterImpl(this,realm);
  setSupportActionBar(toolbar);
  getSupportActionBar().setDisplayShowTitleEnabled(false);
  ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
      this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
  drawer.setDrawerListener(toggle);
  toggle.syncState();
  View headerLayout= navigationView.inflateHeaderView(R.layout.main_slide);
  navigationView.setNavigationItemSelectedListener(this);
  presenter.init(searchView,headerLayout);
}

代码示例来源:origin: loonggg/MaterialDesignDemo

navigationView.setNavigationItemSelectedListener(this);
View navHeaderView = navigationView.inflateHeaderView(R.layout.header_layout);

代码示例来源:origin: Leaking/WeGit

ButterKnife.bind(this);
headerView = navigationView.inflateHeaderView(R.layout.nav_header);
img_avatar = (CircleImageView) headerView.findViewById(R.id.avatar);
txt_user = (TextView) headerView.findViewById(R.id.headerText);

代码示例来源:origin: rohanoid5/Muzesto

View header = navigationView.inflateHeaderView(R.layout.nav_header);

代码示例来源:origin: nvllsvm/Audinaut

});
drawerHeader = drawerList.inflateHeaderView(R.layout.drawer_header);
drawerHeader.setOnClickListener(v -> {
  if (showingTabs) {

代码示例来源:origin: WomenWhoCode/WomenWhoCode

View headerLayout = navigationView.inflateHeaderView(R.layout.nav_header);

相关文章