1. 程式人生 > >單純的側滑,無任何東西!!!

單純的側滑,無任何東西!!!

#1.
package com.bw.ymy.cehua;

import android.support.v4.view.ViewPager;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MenuItem;

public class MainActivity extends AppCompatActivity {
private ViewPager viewpage1;
private DrawerLayout drawer;
private ActionBarDrawerToggle toggle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
viewpage1=findViewById(R.id.viewpage1);
drawer=findViewById(R.id.drawer);
ActionBar bar=getSupportActionBar();
bar.setDisplayHomeAsUpEnabled(true);
toggle=new ActionBarDrawerToggle(this,drawer,R.string.open,R.string.close);
drawer.addDrawerListener(toggle);
toggle.syncState();

}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if(toggle.onOptionsItemSelected(item))
    {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

}
//佈局

<?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:layout_width=“match_parent”
android:layout_height=“match_parent”
tools:context=".MainActivity"
android:id="@+id/drawer"

<android.support.v4.view.ViewPager
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/viewpage1"
    
    ></android.support.v4.view.ViewPager>

<fragment
    android:layout_width="200dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    class="com.bw.ymy.cehua.Blank"
    />

</android.support.v4.widget.DrawerLayout>