fragment侧滑

XML:




    

    
    


values文件夹中的strings.xml:

	    kai
    guan

Activity:

private DrawerLayout drawerLayout;
    private ActionBarDrawerToggle toggle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //获取资源ID
        drawerLayout = findViewById(R.id.draw);
       initdata();
    }

    private void initdata() {
        //允许标题栏展示左边icon
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        //actionbar和drawlayout之间的中间人,创建中间人
        toggle = new ActionBarDrawerToggle(this,drawerLayout,R.string.kai,R.string.guan);
        //同步
        drawerLayout.addDrawerListener(toggle);
        toggle.syncState();
    }
    //点击标题栏左上角的东西
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (toggle.onOptionsItemSelected(item)){
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

你可能感兴趣的:(fragment侧滑)