Java Code Examples for com.google.android.material.navigation.NavigationView#getHeaderView()

The following examples show how to use com.google.android.material.navigation.NavigationView#getHeaderView() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java    From NClientV2 with Apache License 2.0 5 votes vote down vote up
private void changeNavigationImage(NavigationView navigationView) {
    boolean light=Global.getTheme()== Global.ThemeScheme.LIGHT;
    View view=navigationView.getHeaderView(0);
    ImageView imageView=view.findViewById(R.id.imageView);
    View layoutHeader=view.findViewById(R.id.layout_header);
    ImageDownloadUtility.loadImage(light?R.drawable.ic_logo_dark :R.drawable.ic_logo,imageView);
    layoutHeader.setBackgroundResource(light?R.drawable.side_nav_bar_light:R.drawable.side_nav_bar_dark);
}
 
Example 2
Source File: DriverHome.java    From UberClone with MIT License 5 votes vote down vote up
public void initDrawer(){
    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 navigationHeaderView=navigationView.getHeaderView(0);
    TextView tvName=(TextView)navigationHeaderView.findViewById(R.id.tvDriverName);
    TextView tvStars=(TextView)navigationHeaderView.findViewById(R.id.tvStars);
    CircleImageView imageAvatar=(CircleImageView) navigationHeaderView.findViewById(R.id.imageAvatar);

    tvName.setText(Common.currentUser.getName());
    if(Common.currentUser.getRates()!=null &&
            !TextUtils.isEmpty(Common.currentUser.getRates()))
        tvStars.setText(Common.currentUser.getRates());

     if(isLoggedInFacebook)
        Picasso.get().load("https://graph.facebook.com/" + Common.userID + "/picture?width=500&height=500").into(imageAvatar);
    else if(account!=null)
        Picasso.get().load(account.getPhotoUrl()).into(imageAvatar);

    if(Common.currentUser.getAvatarUrl()!=null &&
            !TextUtils.isEmpty(Common.currentUser.getAvatarUrl()))
    Picasso.get().load(Common.currentUser.getAvatarUrl()).into(imageAvatar);
}
 
Example 3
Source File: Home.java    From UberClone with MIT License 5 votes vote down vote up
public void initDrawer(){
    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 navigationHeaderView=navigationView.getHeaderView(0);
    TextView tvName=(TextView)navigationHeaderView.findViewById(R.id.tvRiderName);
    TextView tvStars=(TextView)findViewById(R.id.tvStars);
    CircleImageView imageAvatar=(CircleImageView) navigationHeaderView.findViewById(R.id.imgAvatar);

    tvName.setText(Common.currentUser.getName());
    if(Common.currentUser.getRates()!=null &&
            !TextUtils.isEmpty(Common.currentUser.getRates()))
        tvStars.setText(Common.currentUser.getRates());

    if(isLoggedInFacebook)
        Picasso.get().load("https://graph.facebook.com/" + Common.userID + "/picture?width=500&height=500").into(imageAvatar);
    else if(account!=null)
        Picasso.get().load(account.getPhotoUrl()).into(imageAvatar);
    if(Common.currentUser.getAvatarUrl()!=null &&
            !TextUtils.isEmpty(Common.currentUser.getAvatarUrl()))
        Picasso.get().load(Common.currentUser.getAvatarUrl()).into(imageAvatar);
}
 
Example 4
Source File: MainActivity.java    From MHViewer with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate2(@Nullable Bundle savedInstanceState) {
    setContentView(R.layout.activity_main);

    mDrawerLayout = (EhDrawerLayout) ViewUtils.$$(this, R.id.draw_view);
    mNavView = (NavigationView) ViewUtils.$$(this, R.id.nav_view);
    mRightDrawer = (FrameLayout) ViewUtils.$$(this, R.id.right_drawer);
    View headerLayout = mNavView.getHeaderView(0);
    mAvatar = (LoadImageView) ViewUtils.$$(headerLayout, R.id.avatar);
    mDisplayName = (TextView) ViewUtils.$$(headerLayout, R.id.display_name);
    mChangeTheme = (Button) ViewUtils.$$(this, R.id.change_theme);

    mDrawerLayout.setStatusBarColor(ResourcesUtils.getAttrColor(this, R.attr.colorPrimaryDark));
    // Pre-L need shadow drawable
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow_left, Gravity.LEFT);
        mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow_right, Gravity.RIGHT);
    }

    updateProfile();

    if (mNavView != null) {
        mNavView.setNavigationItemSelectedListener(this);
    }

    mChangeTheme.setText(getThemeText());
    mChangeTheme.setOnClickListener(v -> {
        Settings.putTheme(getNextTheme());
        ((EhApplication) getApplication()).recreate();
    });

    if (savedInstanceState == null) {
        onInit();
        CommonOperations.checkUpdate(this, false);
        checkDownloadLocation();
        if (Settings.getCellularNetworkWarning()) {
            checkCellularNetwork();
        }
    } else {
        onRestore(savedInstanceState);
    }

    EhTagDatabase.update(this);
}
 
Example 5
Source File: DrawerAccountsService.java    From kolabnotes-android with GNU Lesser General Public License v3.0 4 votes vote down vote up
public DrawerAccountsService(NavigationView view) {
    this.headerView = view.getHeaderView(0);
    this.nav = view;
}
 
Example 6
Source File: MainActivity.java    From EhViewer with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate2(@Nullable Bundle savedInstanceState) {
    setContentView(R.layout.activity_main);

    mDrawerLayout = (EhDrawerLayout) ViewUtils.$$(this, R.id.draw_view);
    mNavView = (NavigationView) ViewUtils.$$(this, R.id.nav_view);
    mRightDrawer = (FrameLayout) ViewUtils.$$(this, R.id.right_drawer);
    View headerLayout = mNavView.getHeaderView(0);
    mAvatar = (LoadImageView) ViewUtils.$$(headerLayout, R.id.avatar);
    mDisplayName = (TextView) ViewUtils.$$(headerLayout, R.id.display_name);
    mChangeTheme = (Button) ViewUtils.$$(this, R.id.change_theme);

    mDrawerLayout.setStatusBarColor(ResourcesUtils.getAttrColor(this, R.attr.colorPrimaryDark));
    // Pre-L need shadow drawable
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow_left, Gravity.LEFT);
        mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow_right, Gravity.RIGHT);
    }

    updateProfile();

    if (mNavView != null) {
        mNavView.setNavigationItemSelectedListener(this);
    }

    mChangeTheme.setText(getThemeText());
    mChangeTheme.setOnClickListener(v -> {
        Settings.putTheme(getNextTheme());
        ((EhApplication) getApplication()).recreate();
    });

    if (savedInstanceState == null) {
        onInit();
        CommonOperations.checkUpdate(this, false);
        checkDownloadLocation();
        if (Settings.getCellularNetworkWarning()) {
            checkCellularNetwork();
        }
    } else {
        onRestore(savedInstanceState);
    }

    EhTagDatabase.update(this);
}