2013-09-22 74 views
1

我很新的android和facebook plugin.trying按照facebook
开发人员网站中提到的步骤操作。 https://developers.facebook.com/docs/android/scrumptious/authenticate/
转到步骤3android facebook UserSettingsFragment无法正常工作

I followed it without missing any steps. 
    However, I do not see a menu at the bottom when i am logged in.Any help? 

    Below is the snippet of important codes and xml. 
@Override 
    public boolean onPrepareOptionsMenu(Menu menu) { 
     // only add the menu when the selection fragment is showing 
     if (fragments[SELECTION].isVisible()) { 
      if (menu.size() == 0) { 
       Log.d("onPrepareOptionsMenu","Yes"); 

       settings = menu.add(R.string.settings); 
      } 
      return true; 
     } else { 
      menu.clear(); 
      settings = null; 
     } 
     return false; 
    } 

继main.xml中

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <fragment android:name="com.punit.xxx.SelectionFragment" 
      android:id="@+id/selectionFragment" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
    <fragment android:name="com.punit.xxx.SplashFragment" 
      android:id="@+id/splashFragment" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
    <fragment android:name="com.facebook.widget.UserSettingsFragment" 
      android:id="@+id/userSettingsFragment" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
</LinearLayout> 

我试图把一些日志,发现OnPrepareotionsMenu永远不会被调用。

回答

0
  1. 从代码中删除onPrepareOptionsMenu(菜单菜单)。
  2. 添加
     *item 
        android:id="@+id/action_logout" 
        MyNews:showAsAction="never" 
        android:actionProviderClass="android.support.v7.widget.ShareActionProvider" 
        android:orderInCategory="10" 
        android:title="@string/logout"/*

注:更换*与<或>。

  1. 添加

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) {

    switch(item.getItemId()){ 
    case R.id.action_logout: 
        showSettingsFragment(); 
        return true; 
    } 
    return false; 
    

    } 公共无效showSettingsFragment(){ showFragment(设定,真); }

它为我工作。

+0

是应该说android而不是MyNews? – user2456977

+0

并且您是否在布局xml或drawable中添加了?或者别的地方? – user2456977