samedi 1 août 2015

Wrong navigation drawer appearing

I'm trying to show a navigation drawer from this tutorial (http://ift.tt/1voac2P) where the header is hidden on phone and the header is visible on tablets but for some reason the header appears on both phone and tablets, which is not what I want. What I'm aiming for is to keep the header visible on tablets (mTwoPane) but hide it on phones. What within my code needs to change in rode to achieve this?

FragmentMain.java

public class FragmentMainList extends android.support.v4.app.Fragment {

    public FragmentMainList() {
        // Required empty constructor
    }

    ListView list_main;

    private AccountHeader headerResult = null;
    private Drawer result = null;

    public boolean mTwoPane;

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
        View v = inflater.inflate(R.layout.fragment_main, container, false);

    headerResult = new AccountHeaderBuilder()
            .withActivity(getActivity())
            .withCompactStyle(true)
            .withHeaderBackground(R.color.wc)
            .withProfileImagesVisible(false)
            .withTextColor(Color.parseColor("#FFFFFF"))
            .withSelectionListEnabled(false)

            .addProfiles(
                    new ProfileDrawerItem().withName("Mike Penz").withEmail("mikepenz@gmail.com")
            )
            .build();

    result = new DrawerBuilder()
            .withActivity(getActivity())
            .withAccountHeader(headerResult)
            .withTranslucentStatusBar(false)
            .withActionBarDrawerToggle(false)
            .withSelectedItem(-1)
            .addDrawerItems(
                    new SectionDrawerItem().withName(R.string.greeting).setDivider(false),
                    new PrimaryDrawerItem().withName(R.string.greeting).withIdentifier(1).withCheckable(false),
            )
            .build();

        return v;
    }
}

MainActivity.java

public class MainActivity extends AppCompatActivity {

    private boolean mTwoPane;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        FragmentMainList newFragment = new FragmentMainList();
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.master_container, newFragment);
        transaction.commit();

        result = new DrawerBuilder()
            .withActivity(this)
            .withAccountHeader(headerResult)
            .withTranslucentStatusBar(false)
            .withActionBarDrawerToggle(false)
            .withSelectedItem(-1)
            .addDrawerItems(
                    new SectionDrawerItem().withName(R.string.greeting).setDivider(false),
                    new PrimaryDrawerItem().withName(R.string.greeting).withIdentifier(1).withCheckable(false),
                    new SectionDrawerItem().withName(R.string.greeting)
            )
            .build();

        if (findViewById(R.id.detail_container) != null) {
            mTwoPane = true;
        }
    }
}

activity_main.xml

<RelativeLayout
    xmlns:android="http://ift.tt/nIICcg"
    android:id="@+id/master_container"
    android:name="com.apptacularapps.exitsexpertlondonlite.FragmentMainList"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

activity_main.xml (sw600dp)

<LinearLayout xmlns:android="http://ift.tt/nIICcg"
    xmlns:tools="http://ift.tt/LrGmb4"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:divider="@drawable/divider_vertical"
    android:showDividers="middle"
    android:baselineAligned="false"
    tools:context=".MainActivity" >

    <RelativeLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:id="@+id/master_container"/>

    <FrameLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="3"
        android:id="@+id/detail_container"/>

</LinearLayout>

fragment_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/fragmentmainlist" >

    <ListView
        android:id="@+id/list_main"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbarThumbVertical="@drawable/light_scrollbar" />

</LinearLayout>

Aucun commentaire:

Enregistrer un commentaire