Aller au contenu
View in the app

A better way to browse. Learn more.

Forum de Frandroid

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Acceder a un header d'un drawerlayout

Featured Replies

Posté(e)

Bonjour,

Je n'arrive pas a acceder au TextView que l'on pourrait trouver dans un LinearLayout qui lui meme se trouve dans le NavigationView du drawerLayout...

J'ai posté sur StackOverflow sans réel succes, alors je me tourne vers vous : 

http://stackoverflow.com/questions/34518757/change-textview-in-drawerlayout

ActivityMain :

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:fitsSystemWindows="true" tools:openDrawer="start">

    <include layout="@layout/app_bar_main" android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <android.support.design.widget.NavigationView android:id="@+id/nav_view"
        android:layout_width="wrap_content" android:layout_height="match_parent"
        android:layout_gravity="start" android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main" app:menu="@menu/activity_main_drawer" />

</android.support.v4.widget.DrawerLayout>

et le nav_header_main 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="@dimen/nav_header_height"
    android:background="@drawable/side_nav_bar"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:theme="@style/ThemeOverlay.AppCompat.Dark" android:orientation="vertical"
    android:gravity="bottom">

    <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:paddingTop="@dimen/nav_header_vertical_spacing"
        android:src="@drawable/side" android:id="@+id/imageView" />

    <TextView android:layout_width="match_parent" android:layout_height="wrap_content"
        android:id="@+id/labelConnection"
        android:paddingTop="@dimen/nav_header_vertical_spacing" android:text="Se connecter..."
        android:textAppearance="@style/TextAppearance.AppCompat.Body1"

        android:onClick="onClick"
        android:clickable="true" />


</LinearLayout>

Je n'arrive pas a acceder au textview qui se nomme LabelConnection, a chaque essai, je tombe sur un nullPointerException......

 

Des idées?

  • 1 month later...
Posté(e)

Si tu fais un findViewById dans ton activity, tu ne le trouveras pas car il va le chercher dans le root layout (donc ton DrawerLayout)

 

Il faut que tu récupères d'abord ton object NavigationView (appelle le mNavigationView par exemple) puis tu récupère son header :

mNavigationView.findViewById(R.id.labelConnection) devrait fonctionner.

 

Ou bien, je n'ai pas vérifié, mais tu as peut être même un getter sur NavigationView : View mHeader = mNavigationView.getHeader() ... à vérifier

Rejoignez la conversation

Vous pouvez poster maintenant et vous enregistrez plus tard. Si vous avez un compte, connectez-vous maintenant pour poster.

Invité
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Répondre à ce sujet…

Account

Navigation

Rechercher

Rechercher

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.