Fragment侧滑

XML:



    



fragmentonexml:


values文件夹中strings.xml:


    cehua
    kai
    guan

Fragment类:

    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.fragmentone,container,false);
        return view;

    }

Activity:

    private DrawerLayout drawerLayout;
    private ActionBar actionBar;
    private ActionBarDrawerToggle toggle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //获取资源ID
        drawerLayout = findViewById(R.id.draw);
        actionBar = getSupportActionBar();
        //顶部的开启按钮
        actionBar.setDisplayHomeAsUpEnabled(true);
        toggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.kai, R.string.guan);
        //同步
        toggle.syncState();
        drawerLayout.addDrawerListener(toggle);

    }
    //点击事件
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (toggle.onOptionsItemSelected(item)){
            return  true;
        }
        return super.onOptionsItemSelected(item);
    }

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