Java 如何通过活动中的ID在导航视图中找到视图?
我有一个活动布局,它调用另一个xml文件作为标题。我想在Java 如何通过活动中的ID在导航视图中找到视图?,java,c#,android,xamarin,findviewbyid,Java,C#,Android,Xamarin,Findviewbyid,我有一个活动布局,它调用另一个xml文件作为标题。我想在nav_header_main中获取设置的图像视图的id引用,但我无法访问它 主要活动: <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tool
nav_header_main
中获取设置的图像视图的id引用,但我无法访问它
主要活动:
<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">
<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>
有没有办法绕过它并获得推荐人?似乎我错过了一件简单的事情。导航视图导航视图=(导航视图)findViewById(R.id.nav_视图); View hView=navigationView.getHeaderView(0); TextView导航用户=(TextView)hView.findViewById(R.id.nav_名称);
nav_user.setText(用户)代码>如前所述,我确实错过了一些简单的事情。我自己无法接通。。谢谢!另一个
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="@dimen/nav_header_height"
android:background="@drawable/side_nav_bar"
android:gravity="bottom"
android:orientation="vertical"
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">
<ImageButton
android:background = "@drawable/roundedbuttonwhite"
android:id="@+id/LogoButtonView"
android:layout_width="80dp"
android:layout_height="80dp"
android:scaleType="fitCenter"
android:paddingTop="15dp"
android:src="@drawable/logoimg" />
</LinearLayout>
logoImageButton = FindViewById<ImageButton>(Resource.Id.LogoButtonView); //Returns null
logoImageButton.SetOnClickListener(this);
nav_draw.getMenu().findItem(R.id.LogoButtonView).setVisible(false);