當前位置: 首頁>>代碼示例>>Java>>正文


Java NavigationView.getHeaderView方法代碼示例

本文整理匯總了Java中android.support.design.widget.NavigationView.getHeaderView方法的典型用法代碼示例。如果您正苦於以下問題:Java NavigationView.getHeaderView方法的具體用法?Java NavigationView.getHeaderView怎麽用?Java NavigationView.getHeaderView使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.support.design.widget.NavigationView的用法示例。


在下文中一共展示了NavigationView.getHeaderView方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initNavDrawer

import android.support.design.widget.NavigationView; //導入方法依賴的package包/類
/**
 * Initialize NavDrawer
 */
private void initNavDrawer() {
    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(mToolbar);

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, mToolbar, 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);
    navigationHeader = navigationView.getHeaderView(0);

    accountID = (TextView) navigationHeader.findViewById(R.id.nav_drawer_account_id);
    username = (TextView) navigationHeader.findViewById(R.id.nav_drawer_username);
    navHeader = (LinearLayout) navigationHeader.findViewById(R.id.nav_drawer);
}
 
開發者ID:d0pam1n,項目名稱:DoorPhone,代碼行數:22,代碼來源:BaseActivity.java

示例2: setNavigationHeader

import android.support.design.widget.NavigationView; //導入方法依賴的package包/類
private void setNavigationHeader() {
    NavigationView navigationView = findViewById(R.id.nav_view);
    View header = navigationView.getHeaderView(0);
    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
    if(user!=null) {
        ((TextView) header.findViewById(R.id.nav_email)).setText(user.getEmail());
        ((TextView) header.findViewById(R.id.nav_name)).setText(user.getDisplayName());
       ImageView image =  header.findViewById(R.id.nav_profile_image);

        Glide.with(this)
                .applyDefaultRequestOptions(RequestOptions.circleCropTransform())
                .asBitmap()
                .load(user.getPhotoUrl())
                .into(image);
    }
}
 
開發者ID:coder3101,項目名稱:gdgApp,代碼行數:17,代碼來源:MainActivity.java

示例3: loadProfileInformation

import android.support.design.widget.NavigationView; //導入方法依賴的package包/類
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());

    }
 
開發者ID:Amay-Mishra,項目名稱:Trackr,代碼行數:19,代碼來源:MainMenuActivity.java

示例4: loadProfileInformation

import android.support.design.widget.NavigationView; //導入方法依賴的package包/類
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);
        userId = String.valueOf(currentUser.getId());
        authToken = currentUser.getAuthToken();

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

    }
 
開發者ID:Amay-Mishra,項目名稱:Trackr,代碼行數:21,代碼來源:PermissionManagerActivity.java

示例5: onCreate

import android.support.design.widget.NavigationView; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    // Initialize navigation drawer
    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) findViewById(R.id.nav_view);
    navigationHeader = navigationView.getHeaderView(0);

    getDataFromIntent();

    initializeDrawer();
}
 
開發者ID:a-deda,項目名稱:share-location,代碼行數:22,代碼來源:MainActivity.java

示例6: drawToolbar

import android.support.design.widget.NavigationView; //導入方法依賴的package包/類
/**
 * 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);

}
 
開發者ID:CMPUT301F17T13,項目名稱:cat-is-a-dog,代碼行數:29,代碼來源:BaseDrawerActivity.java

示例7: setupView

import android.support.design.widget.NavigationView; //導入方法依賴的package包/類
@Override
protected void setupView() {
    Toolbar 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 = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    View headerView = navigationView.getHeaderView(0);
    authenticatedLayout = headerView.findViewById(R.id.authenticated_layout);
    unauthenticatedLayout = headerView.findViewById(R.id.unauthenticated_layout);
    nameText = (TextView) headerView.findViewById(R.id.name_text);
    headerView.findViewById(R.id.show_login_button).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(MainActivity.this, LoginActivity.class);
            startActivity(intent);
        }
    });

    // Set up and select first item
    navigationView.setCheckedItem(R.id.nav_summary);
    presenter.navigateToSummaryPage();
}
 
開發者ID:mocircle,項目名稱:devsuite-android,代碼行數:31,代碼來源:MainActivity.java

示例8: onCreate

import android.support.design.widget.NavigationView; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    context = this;
    setContentView(R.layout.activity_main);
    try {
        saveLogcatToFile(this);
    } catch (IOException e) {
        e.printStackTrace();
    }
    // Ensure Google Play services framework is installed
    int gAAResult = GoogleApiAvailability
            .getInstance()
            .isGooglePlayServicesAvailable(this);
    if(gAAResult == ConnectionResult.SUCCESS){
        Log.d(TAG, "Play services available");
    } else {
        GoogleApiAvailability
                .getInstance()
                .getErrorDialog(this, gAAResult, REQUEST_CODE);
    }
    notifications = new ArrayList<>();
    notifAdapter = new NotificationAdapter(this, notifications);


    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.setDrawerListener(toggle);
    //toggle.setDrawerIndicatorEnabled(false);

    //toggle.setHomeAsUpIndicator(R.drawable.csi_ic_actionbar);
    toggle.syncState();

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

    //Load profile picture and name of signed in user
    View navHeader = navigationView.getHeaderView(0);
    ImageView profilePic = navHeader.findViewById(R.id.user_dp_iv);
    TextView nameTv = navHeader.findViewById(R.id.user_name_tv);

    SharedPreferences sf = getSharedPreferences(getString(R.string.USER_INFO),MODE_PRIVATE);
    String name = sf.getString(getString(R.string.pref_key_name),getString(R.string.csi_fan));
    String picUrl = sf.getString(getString(R.string.pref_key_pic_url),getString(R.string.pref_default_pic));

    nameTv.setText(name);
    profilePic.setOnClickListener(this);
    if(!URLUtil.isValidUrl(picUrl)){
        if(picUrl.equalsIgnoreCase("female"))
            profilePic.setImageDrawable(getResources().getDrawable(R.drawable.ic_default_female_avatar));
    }
    else {
        Glide
                .with(this)
                .load(picUrl)
                .into(profilePic);
    }

    HomeFragment homeFragment = new HomeFragment();
    getSupportFragmentManager().beginTransaction().add(R.id.frames,homeFragment).commit();

    GoogleSignInOptions gso = new GoogleSignInOptions
            .Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestEmail()
            .build();

}
 
開發者ID:CSI-KJSCE,項目名稱:CSI-KJSCEOfficial,代碼行數:72,代碼來源:MainActivity.java

示例9: init

import android.support.design.widget.NavigationView; //導入方法依賴的package包/類
public void init(){
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

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

    navHeader = navigationView.getHeaderView(0);
    txtName = (TextView) navHeader.findViewById(R.id.name);
    txtSubName = (TextView) navHeader.findViewById(R.id.subname);
    imgNavHeaderBg = (ImageView) navHeader.findViewById(R.id.img_header_bg);
    imgProfile = (ImageView) navHeader.findViewById(R.id.img_profile);

    viewPager = (ViewPager)findViewById(R.id.main_view_pager);

    quiz_layout= (LinearLayout) findViewById(R.id.quiz_layout);
    gallery_layout= (LinearLayout) findViewById(R.id.gallery_layout);
    map_layout= (LinearLayout) findViewById(R.id.map_layout);
    newsfeed_layout= (LinearLayout) findViewById(R.id.newsfeed_layout);
    coreteam_layout= (LinearLayout) findViewById(R.id.coreteam_layout);
    aboutnimbus_layout= (LinearLayout) findViewById(R.id.aboutnimbus_layout);
    teams_layout= (LinearLayout) findViewById(R.id.teams_layout);
    feedback_layout= (LinearLayout) findViewById(R.id.feedback_layout);
    contributor_layout= (LinearLayout) findViewById(R.id.contributor_layout);
    sponsor_layout= (LinearLayout) findViewById(R.id.sponsor_layout);
    workshop_layout= (LinearLayout) findViewById(R.id.workshop_layout);
    bottomNavigationView= (BottomNavigationView) findViewById(R.id.bottom_navigation);

}
 
開發者ID:appteam-nith,項目名稱:Nimbus,代碼行數:30,代碼來源:MainActivity.java

示例10: initView

import android.support.design.widget.NavigationView; //導入方法依賴的package包/類
private void initView() {
    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    //這裏注意設置標題要在setsupportactionbar方法前調用才會有效
    mToolbar.setTitle(" ");
    setSupportActionBar(mToolbar);
    mToolbar.setNavigationIcon(R.mipmap.home3);
    mToolbar.setLogo(R.mipmap.toolicon2);
    mToolbar.setOnMenuItemClickListener(mOnMenuItemClickListener);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mNavigationView = (NavigationView) findViewById(R.id.nav_view);
    //以下兩行代碼是如何獲取navigationView中子view的方式
    View headerView = mNavigationView.getHeaderView(0);
    textViewLogin = (TextView) headerView.findViewById(R.id.tv_login);
    textViewShare = (TextView) findViewById(R.id.share_main);
    //mViewPager = (ViewPager) findViewById(R.id.vp_main);
    mTabLayout = (TabLayout) findViewById(R.id.tab_main);
    bottom_main_navigation = (BottomNavigationView) findViewById(R.id.bottom_main_navigation);
    //該方法調用helper類去掉大於3時的動畫
    BottomNavigationViewHelper.disableShiftMode(bottom_main_navigation);
    MenuItem item = bottom_main_navigation.getMenu().getItem(0);
    bottom_main_navigation.setOnNavigationItemSelectedListener(this);
    onNavigationItemSelected(item);//默認選中第一個
    mCircleImageView = (CircleImageView) headerView.findViewById(R.id.icon_image);
    mFilter = new IntentFilter();
    mFilter.addAction("com.songchao.mybilibili.notifilogin");
    mFilter.addAction("com.songchao.mybilibili.notifiout");
    mNotifyLoginUIReceiver = new NotifyLoginUIReceiver();
    registerReceiver(mNotifyLoginUIReceiver,mFilter);
    //應該把SharedPreferences封裝為一個工具類,這樣會減少很多重複代碼
    mPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    mEditor = mPreferences.edit();
}
 
開發者ID:AndroidBoySC,項目名稱:Mybilibili,代碼行數:33,代碼來源:MainActivity.java

示例11: onCreate

import android.support.design.widget.NavigationView; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Intent intent = getIntent();
    String mEmail = intent.getStringExtra("user_email"),
            mName = mEmail.split("@")[0];

    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);
    View hView =  navigationView.getHeaderView(0);

    TextView nav_user = (TextView) hView.findViewById(R.id.nav_header_user_name);
    nav_user.setText(mName);

    TextView nav_email = (TextView) hView.findViewById(R.id.nav_header_user_email);
    nav_email.setText(mEmail);

    navigationView.setNavigationItemSelectedListener(this);
    displayView(R.id.nav_courses);
}
 
開發者ID:imondrag,項目名稱:study-buddy,代碼行數:40,代碼來源:MainActivity.java

示例12: setupDrawerLayout

import android.support.design.widget.NavigationView; //導入方法依賴的package包/類
private void setupDrawerLayout() {
    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) findViewById(R.id.nav_drawer_view);
    navigationView.setNavigationItemSelectedListener(this);
    View header=navigationView.getHeaderView(0);
    lastSyncDateView = (TextView) header.findViewById(R.id.text_view_last_sync);
    NavigationMenuView navigationMenuView = (NavigationMenuView) navigationView.getChildAt(0);
       if (navigationMenuView != null) {
            navigationMenuView.setVerticalScrollBarEnabled(false);
      }
}
 
開發者ID:graviton57,項目名稱:TVGuide,代碼行數:16,代碼來源:MainActivity.java

示例13: onCreate

import android.support.design.widget.NavigationView; //導入方法依賴的package包/類
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        dbManager = DBManager.getInstance(HomeActivity.this);
        toolbar = (Toolbar)findViewById(R.id.home_activity_toolbar);
        setSupportActionBar(toolbar);
        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        navView = (NavigationView) findViewById(R.id.nav_view);
        View headerView = navView.getHeaderView(0);
        navHeadIv = (ImageView)headerView.findViewById(R.id.nav_head_bg_iv);
        loadBingPic();
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setHomeAsUpIndicator(R.drawable.drawer_menu);
        }
        refreshNightModeTitle();
        navView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(MenuItem item) {
                mDrawerLayout.closeDrawers();
                switch (item.getItemId()){
                    case R.id.nav_theme:
                        isStartTheme = true;
                        Intent intentTheme = new Intent(HomeActivity.this,ThemeActivity.class);
                        startActivity(intentTheme);
                        break;
                    case R.id.nav_night_mode:
                        int preTheme = 0;
                        if(MyMusicUtil.getNightMode(HomeActivity.this)){
                            //當前為夜間模式,則恢複之前的主題
                            MyMusicUtil.setNightMode(HomeActivity.this,false);
                            preTheme = MyMusicUtil.getPreTheme(HomeActivity.this);
                            MyMusicUtil.setTheme(HomeActivity.this,preTheme);
                        }else {
                            //當前為白天模式,則切換到夜間模式
                            MyMusicUtil.setNightMode(HomeActivity.this,true);
                            MyMusicUtil.setTheme(HomeActivity.this,ThemeActivity.THEME_SIZE-1);
                        }
//                        Intent intentNight = new Intent(HomeActivity.this,HomeActivity.class);
//                        startActivity(intentNight);
                        recreate();
                        refreshNightModeTitle();
//                        overridePendingTransition(R.anim.start_anim,R.anim.out_anim);
                        break;
                    case R.id.nav_about_me:
                        Intent aboutTheme = new Intent(HomeActivity.this,AboutActivity.class);
                        startActivity(aboutTheme);
                        break;
                    case R.id.nav_logout:
                        finish();
                        Intent intentBroadcast = new Intent(MusicPlayerService.PLAYER_MANAGER_ACTION);
                        intentBroadcast.putExtra(Constant.COMMAND, Constant.COMMAND_RELEASE);
                        sendBroadcast(intentBroadcast);
                        Intent stopIntent = new Intent(HomeActivity.this,MusicPlayerService.class);
                        stopService(stopIntent);
                        break;
                }
                return true;
            }
        });
        init();

        Intent startIntent = new Intent(HomeActivity.this,MusicPlayerService.class);
        startService(startIntent);

    }
 
開發者ID:lijunyandev,項目名稱:MeetMusic,代碼行數:69,代碼來源:HomeActivity.java

示例14: onCreate

import android.support.design.widget.NavigationView; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    mHandler = new Handler();

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

    // Navigation view header
    navHeader = navigationView.getHeaderView(0);
    txt_nama = (TextView) navHeader.findViewById(R.id.txt_nama);
    txt_instansi = (TextView) navHeader.findViewById(R.id.txt_instansi);
    imgNavHeaderBg = (ImageView) navHeader.findViewById(R.id.img_header_bg);
    imgProfile = (ImageView) navHeader.findViewById(R.id.img_profile);

    // load toolbar titles from string resources
    activityTitles = getResources().getStringArray(R.array.nav_item_activity_titles);

    // initializing navigation menu
    setUpNavigationView();

    try {
        realmHelper = new RealmHelper(MainActivity.this);

        profilModels = realmHelper.findAllProfil();

        if (!realmHelper.findAllProfil().isEmpty()){
            txt_nama.setText(profilModels.get(0).getNama());
            txt_instansi.setText(profilModels.get(0).getInstansi());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }


    if (savedInstanceState == null) {
        navItemIndex = 0;
        CURRENT_TAG = TAG_BERANDA;
        loadHomeFragment();
    }
}
 
開發者ID:setakarim,項目名稱:ingetin,代碼行數:46,代碼來源:MainActivity.java

示例15: onCreate

import android.support.design.widget.NavigationView; //導入方法依賴的package包/類
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_navigation_view);
        mToolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(mToolbar);
        mDrawerLayout = (DrawerLayout) findViewById(R.id.DrawerLayout);
        mDrawerToggle = new ActionBarDrawerToggle(
                this,                  /* host Activity */
                mDrawerLayout,         /* DrawerLayout object */
                mToolbar,
                R.string.drawer_open2,  /* "open drawer" description for accessibility */
                R.string.drawer_close2  /* "close drawer" description for accessibility */
        ) {
            public void onDrawerClosed(View view) {
                getSupportActionBar().setTitle(mTitle);
                invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
            }
            public void onDrawerOpened(View drawerView) {
                getSupportActionBar().setTitle(mDrawerTitle);
                invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
            }
        };
        mDrawerLayout.addDrawerListener(mDrawerToggle);

        mNavigationView = (NavigationView) findViewById(R.id.NavigationView);
//        mNavigationView.setItemIconTintList(null);//顯示Icon原有顏色
        //獲取頭布局文件
        View headerView = mNavigationView.getHeaderView(0);
        TextView mTextView = (TextView) headerView.findViewById(R.id.tv_header_title);
        mTextView.setText("NavigationView");
        mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(MenuItem item) {
                //在這裏處理item的點擊事件

                switch(item.getItemId()){
                    case R.id.nav_camera:
                        Snackbar.make(mNavigationView,"照相", Snackbar.LENGTH_LONG).show();
                        break;
                    case R.id.nav_gallery:
                        Snackbar.make(mNavigationView,"相冊", Snackbar.LENGTH_LONG).show();
                        break;
                    case R.id.nav_slideshow:
                        Snackbar.make(mNavigationView,"視頻", Snackbar.LENGTH_LONG).show();
                        break;
                    case R.id.nav_manage:
                        Snackbar.make(mNavigationView,"工具", Snackbar.LENGTH_LONG).show();
                        break;
                    case R.id.nav_share:
                        Snackbar.make(mNavigationView,"分享", Snackbar.LENGTH_LONG).show();
                        break;
                    case R.id.nav_send:
                        Snackbar.make(mNavigationView,"發送", Snackbar.LENGTH_LONG).show();
                        break;
                }
                mDrawerLayout.closeDrawer(Gravity.LEFT);
                return true;
            }
        });

    }
 
開發者ID:LinweiJ,項目名稱:MaterialDesignWidget,代碼行數:63,代碼來源:NavigationViewActivity.java


注:本文中的android.support.design.widget.NavigationView.getHeaderView方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。