亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何通過活動的 ID 在導航視圖中找到視圖?

如何通過活動的 ID 在導航視圖中找到視圖?

斯蒂芬大帝 2022-10-26 16:27:21
我有一個活動布局,它調用另一個 xml 文件作為標題。我想通過 id 中設置的圖像視圖的 id 獲取參考nav_header_main,但我無法訪問它。活動主:<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>nav_header_main:<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">請注意,nav_header_main在activity_layout.我試圖在活動中設置一個 OnClickListener,但我得到一個 NullException,只是因為我無法從活動中訪問該 ImageButton 視圖。logoImageButton = FindViewById<ImageButton>(Resource.Id.LogoButtonView); //Returns nulllogoImageButton.SetOnClickListener(this);有什么辦法可以繞過它并獲得參考嗎?好像我錯過了一件簡單的事情。
查看完整描述

2 回答

?
溫溫醬

TA貢獻1752條經驗 獲得超4個贊

NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); View hView =  navigationView.getHeaderView(0); TextView nav_user = (TextView)hView.findViewById(R.id.nav_name); nav_user.setText(user);

查看完整回答
反對 回復 2022-10-26
?
白衣非少年

TA貢獻1155條經驗 獲得超0個贊

nav_draw.getMenu().findItem(R.id.LogoButtonView).setVisible(false);



查看完整回答
反對 回復 2022-10-26
  • 2 回答
  • 0 關注
  • 143 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號