下面的代码是在OnCreate方法中。
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.nav_header_app_base, null);
textViewUserName = (TextView) view.findViewById(R.id.textViewUserNameDrawer);
textViewUserName.setText("Mr."+" "+sharedPreferences.getString(Constants.FIRST_NAME,"")+" "+sharedPreferences.getString(Constants.LAST_NAME,""));
Xml代码在这里
<?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_app_base"
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_app_base"
app:menu="@menu/activity_app_base_drawer" />
</android.support.v4.widget.DrawerLayout>
nav_header_app_base.xml中有textviewUserName 我可以使用inflacted视图打印textview默认值,但是当我尝试设置它时,它不会反映在视图中。
请帮我解决此问题。