In android how to set navigation drawer header image and name programmatically in class file?

前端 未结 16 920
半阙折子戏
半阙折子戏 2020-12-04 07:53

In android studio 1.4.1, I have created new Navigation Drawer Project which is default.My issue is in this project there is nav_header_main.xml file which is for navigation

16条回答
  •  暖寄归人
    2020-12-04 08:34

       FirebaseAuth firebaseauth = FirebaseAuth.getInstance(); 
    
       NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);   //displays text of header of nav drawer.
        View headerview = navigationView.getHeaderView(0);
    
        TextView tt1 = (TextView) headerview.findViewById(R.id.textview_username);
        tt1.setText(firebaseauth.getCurrentUser().getDisplayName());//username of logged in user.  
    
       TextView tt = (TextView) headerview.findViewById(R.id.textView_emailid);
        tt.setText(firebaseauth.getCurrentUser().getEmail());    //email id of logged in user.
    
        final ImageView img1 = (ImageView) headerview.findViewById(R.id.imageView_userimage);
        Glide.with(getApplicationContext())
                .load(firebaseauth.getCurrentUser().getPhotoUrl()).asBitmap().atMost().error(R.drawable.ic_selfie_point_icon)   //asbitmap after load always.
                .into(new SimpleTarget() {
                    @Override
                    public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) {
                        img1.setImageBitmap(resource);
                    }
                });
    

    I have made this code by myself with some logic...Its 100% working.....pls do upvote my ans.

    The textview and imageview are from @layout/nav_header_main.xml

提交回复
热议问题