簡體   English   中英

如何綁定Activity中NavigationView中的TextView

[英]How to Bind a TextView which is in an NavigationView in an Activity

我們使用android sdk 26和butterknife 8.8.1

HomeActivity有一個導航標題,導航標題還包含一些文本視圖。 是否可以在HomeActivity綁定TextViews

以下是一些描述我的問題的代碼

HomeActivity類具有以下布局

<android.support.v4.widget.DrawerLayout ....

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        .....
        app:headerLayout="@layout/nav_header"
        app:menu="@menu/activity_navigation_drawer" />



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

nav_header中有一些TextView

<LinearLayout ....

    <TextView
        android:id="@+id/userinfo_vo_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="TextView" />


</LinearLayout>

是否可以在HomeActivity綁定userinfo_vo_name文本視圖的id,簡單的BindView失敗

//fails 
@BindView(R.id.userinfo_vo_name)
TextView userinfoName;

當然,我已經打電話給ButterKnife.bind(this); onCreate方法中,但似乎還不夠。

試試這個

NavigationView navigationView = (NavigationView) findViewById(R.id.yournavigationView);        
tvProfileName = (TextView) navigationView.getHeaderView(0).findViewById(R.id.tv_nav_userName);
imgUserProfile = (ImageView) navigationView.getHeaderView(0).findViewById(R.id.profile_image);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM