-2
我在我的活動中包含導航抽屜,並且需要動態地更改導航標題窗口小部件(圖像視圖,文本視圖)值,如加載應用用戶名,個人資料圖片和手機號碼。所以請幫助我做到這一點。 在此先感謝。如何動態更改導航標頭小部件的值?
我在我的活動中包含導航抽屜,並且需要動態地更改導航標題窗口小部件(圖像視圖,文本視圖)值,如加載應用用戶名,個人資料圖片和手機號碼。所以請幫助我做到這一點。 在此先感謝。如何動態更改導航標頭小部件的值?
您可以通過NavigationView
得到標題:
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
View headerView = navigationView.getHeaderView(0);
ImageView drawerImage = (ImageView) headerView.findViewById(R.id.drawer_image);
TextView drawerUsername = (TextView) headerView.findViewById(R.id.drawer_username);
TextView drawerAccount = (TextView) headerView.findViewById(R.id.drawer_account);
drawerImage.setImageDrawable(R.drawable.ic_user);
drawerUsername.setText("User");
drawerAccount.setText("[email protected]");
看看這個NavigationView.getHeaderView()
你可以得到頭視圖
View headerView=navigationView.getHeaderView(0);
TextView nameTv=(TextView)headerView.findViewById(R.id.tvHeaderView);
nameTv.setText("any string")
這對我的作品!非常感謝你。@ Exaqt –