DrawerLayout侧拉并点击侧拉选项

布局(权限design)




    
        
    
    
    
    
    
    
    

main

package com.example.zk2;

import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.example.zk2.fragment.Frag_one;
import com.example.zk2.fragment.Frag_two;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private FrameLayout fragment;
    private TextView yi;
    private TextView er;
    private Frag_one one;
    private Frag_two two;
    private DrawerLayout drawerlayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initData();
        initView();
    }

    private void initData() {
        one = new Frag_one();
        two = new Frag_two();
    }

    private void initView() {
        fragment = (FrameLayout) findViewById(R.id.fragment);
        yi = (TextView) findViewById(R.id.yi);
        yi.setOnClickListener(this);
        er = (TextView) findViewById(R.id.er);
        er.setOnClickListener(this);
        drawerlayout = (DrawerLayout) findViewById(R.id.drawerlayout);
        drawerlayout.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.yi:
                getSupportFragmentManager().beginTransaction().replace(R.id.fragment, one).commit();
                drawerlayout.closeDrawers();
                break;
            case R.id.er:
                getSupportFragmentManager().beginTransaction().replace(R.id.fragment, two).commit();
                drawerlayout.closeDrawers();
                break;
        }
    }
}

 

你可能感兴趣的:(DrawerLayout侧拉并点击侧拉选项)