---
title: "How to control views inside NavigationView Header in Android"  
description: "How to control views inside NavigationView Header in Android"  
author: "Anonymous User"  
published: 2016-01-12  
updated: 2023-06-27  
canonical: https://www.mindstick.com/forum/33861/how-to-control-views-inside-navigationview-header-in-android  
category: "android"  
tags: ["android"]  
reading_time: 2 minutes  

---

# How to control views inside NavigationView Header in Android

I want to implement if there is any way to [control](https://www.mindstick.com/blog/197/asp-dot-net-repeater-control) [views](https://www.mindstick.com/forum/12838/compile-views-in-asp-dot-net-mvc) inside the NavigationView [header](https://www.mindstick.com/articles/336036/explain-about-html-header-body-and-footer-tags)? ([Except](https://www.mindstick.com/blog/144/union-intersection-and-except-operator-in-sql-server) for adding or removing header.)\
For example: In the header, I have a [user](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) avatar. By [default](https://www.mindstick.com/interview/12771/what-is-the-importance-of-default-resources), it displays a [guest](https://www.mindstick.com/blog/11817/how-to-get-backlinks-from-online-guest-blogs) [image](https://www.mindstick.com/articles/23551/an-investigate-distinctive-seafood-restaurant-for-your-image-stamp-character), but after the user [logs](https://answers.mindstick.com/qa/50941/how-to-use-manage-apple-iphone-6s-call-forwarding-conferencing-blocking-caller-id-call-logs-settings) in, the real avatar will be showed.\
How can this be accomplished?

## Replies

### Reply by Aryan Kumar

Sure, here are the steps on how to control views inside navigation view header in Android:

1. Get the navigation view header using the `getHeaderView()` method.
2. Get the view that you want to control from the header.
3. Use the `setXXX()` methods to set the properties of the view.
4. For example, to set the text of a text view, you would use the `setText()` method.

Here is an example of how to control views inside navigation view header in Android:

Code snippet

```plaintext
import android.support.design.widget.NavigationView;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Get the navigation view header.
        NavigationView navigationView = (NavigationView) findViewById(R.id.navigation_view);

        // Get the text view from the header.
        TextView textView = (TextView) navigationView.getHeaderView(0).findViewById(R.id.textView);

        // Set the text of the text view.
        textView.setText("Hello, world!");
    }
}
```

In this example, we get the navigation view header and the text view from the header. Then, we set the text of the text view to "Hello, world!".

### Reply by Anonymous User

After the new support library update (23.1.1),\
You could do this -

```
View header = navigationView.getHeaderView(0)TextView text = (TextView) header.findViewById(R.id.textView);
```

or if you have multiple headers\

```
navigationView.getHeaderCount()
```

\
Ref :[https://code.google.com/p/android/issues/detail?id=190226#c31](https://code.google.com/p/android/issues/detail?id=190226#c31)\
\


---

Original Source: https://www.mindstick.com/forum/33861/how-to-control-views-inside-navigationview-header-in-android

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
