本文整理汇总了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);
}
示例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);
}
}
示例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());
}
示例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());
}
示例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();
}
示例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);
}
示例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();
}
示例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();
}
示例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);
}
示例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();
}
示例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);
}
示例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);
}
}
示例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);
}
示例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();
}
}
示例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;
}
});
}