我有一個簡單NavigationView
中,我試圖表明我的資料圖片。這是我到目前爲止有:Facebook個人資料圖片未顯示在導航標題中?
MainActivity.java:
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Profile profile = Profile.getCurrentProfile();
System.out.println("Profile Id: " + profile.getId());
ProfilePictureView profilePictureView = (ProfilePictureView) findViewById(R.id.profile_image);
if(profilePictureView != null) {
System.out.println("Not null.");
System.out.println("Profile Name: " + profile.getFirstName());
profilePictureView.setProfileId(profile.getId());
}
else {
System.out.println("Null.");
}
}
}
main_activity.xml:
<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_news_feed" 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_news_feed">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/nav_header_news_feed"
android:id="@+id/navigation_header"/>
<ListView
android:id="@+id/friends_list"
android:layout_weight="7"
android:layout_width="match_parent"
android:layout_height="0dp"></ListView>
</LinearLayout>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
nav_header_news_feed.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="@dimen/nav_header_height"
xmlns:facebook="http://schemas.android.com/apk/res-auto"
android:background="@drawable/side_nav_bar"
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"
android:orientation="vertical"
android:gravity="bottom">
<com.facebook.login.widget.ProfilePictureView
android:id="@+id/profile_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
facebook:com_facebook_preset_size="small"/>
</LinearLayout>
我很困惑,因爲我認爲我只需實例化profilePictureView
對象並設置其配置文件ID。我以爲我做的一切都正確,因爲名字與登錄的用戶相匹配,並且我確保用戶ID不爲空。
相反,畫面只是看起來像一個空的Facebook檔案照片時,在現實中,我知道我有一張照片。如果有人能指出我的方向正確,那會很棒。謝謝!
編輯:添加在編輯我的文件,以反映什麼馬蒂亞MAESTRINI建議:
MainActivity.java:
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
private NavigationView navigationView;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
View header = LayoutInflater.from(this).inflate(R.layout.nav_header_news_feed, null);
navigationView.addHeaderView(header);
Profile profile = Profile.getCurrentProfile();
System.out.println("Profile Id: " + profile.getId());
ProfilePictureView profilePictureView = (ProfilePictureView) header.findViewById(R.id.profile_image);
if(profilePictureView != null) {
System.out.println("Not null.");
System.out.println("Profile Name: " + profile.getFirstName());
profilePictureView.setProfileId(profile.getId());
}
else {
System.out.println("Null.");
}
}
}
main_activity.xml:
<include layout="@layout/app_bar_news_feed" 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">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/nav_header_news_feed"
android:id="@+id/navigation_header"/>
<ListView
android:id="@+id/friends_list"
android:layout_weight="7"
android:layout_width="match_parent"
android:layout_height="0dp"></ListView>
</LinearLayout>
</android.support.design.widget.NavigationView>
有你寫的這些'FacebookSdk.sdkInitialize(背景); callbackManager = CallbackManager.Factory.create();在獲得AccessToken之前在onCreate方法中? –
@rushankshah是的,我有,但我已經在我的登錄活動其中,在用戶登錄後,進入到MainActivity.java這樣做。如果我沒有這樣做,AccessToken將爲空。我是否也需要在這個文件中調用這些函數? – user1871869
是您的令牌無效或有登錄後的價值? –