侧拉,抽屉

Android侧拉,抽屉

 

核心方法:   drawer_layout.openDrawer(left_drawer);

 

布局:



    
    

        

 

主页面代码:

public class MainActivity extends AppCompatActivity {

    private DrawerLayout drawer_layout;
    private ListView left_drawer;

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

        drawer_layout = findViewById(R.id.drawer_layout);
        left_drawer = findViewById(R.id.left_drawer);
//        drawer_layout.openDrawer(left_drawer);
        
        
        Button btn = findViewById(R.id.btn);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                drawer_layout.openDrawer(left_drawer);
            }
        });


    }
}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(项目开发,常用布局)