鸿 网 互 联 www.68idc.cn

当前位置 : 服务器租用 > 手机系统开发 > android > >

DrawerLayout一个简单的实例(与ActionBar无关)

来源:互联网 作者:佚名 时间:2013-12-25 11:03
官方的Demo里有DrawerLayout的例子,涉及到ActionBar,这里不用ActionBar,手痒,写个超级简单的小Demo,备着以后或许会用到。 详细的内容,可以访问: 看代码: DrawerActivity.java DrawerActivity extends Activity implements OnClickListener { 2 priva

官方的Demo里有DrawerLayout的例子,,涉及到ActionBar,这里不用ActionBar,手痒,写个超级简单的小Demo,备着以后或许会用到。

详细的内容,可以访问:

看代码:

DrawerActivity.java

DrawerActivity extends Activity implements OnClickListener { 2 private DrawerLayout mDrawerLayout = null; 3 private Button bt1; 4 private Button bt2; 5 private Button bt3; 6 7 @Override onCreate(Bundle savedInstanceState) { 9 super.onCreate(savedInstanceState); 10 setContentView(R.layout.activity_drawer); 11 bt1 = (Button) findViewById(R.id.btn); 12 bt2 = (Button) findViewById(R.id.btn1); 13 bt3 = (Button) findViewById(R.id.btn2); 14 bt1.setOnClickListener(this); 15 bt2.setOnClickListener(this); 16 bt3.setOnClickListener(this); 17 mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); 18 mDrawerLayout.setDrawerListener(new DrawerListener() { 19 20 @Override onDrawerStateChanged(int arg0) { 22 Log.d("David", "onDrawerStateChanged arg0 = " + arg0); 23 } 24 25 @Override onDrawerSlide(View arg0, float arg1) { 27 Log.d("David", "onDrawerSlide arg1 = " + arg1); 28 } 29 30 @Override onDrawerOpened(View arg0) { 32 Log.d("David", "onDrawerOpened"); 33 } 34 35 @Override onDrawerClosed(View arg0) { 37 Log.d("David", "onDrawerClosed"); 38 } 39 }); 40 } 41 42 @Override onClick(View v) { 44 switch (v.getId()) { 45 case R.id.btn: 46 mDrawerLayout.openDrawer(Gravity.LEFT); 47 Toast.makeText(this, "bt1111111111", Toast.LENGTH_LONG).show(); 48 break; 49 case R.id.btn1: 50 Toast.makeText(this, "bt2222222222", Toast.LENGTH_LONG).show(); 51 break; 52 case R.id.btn2: 53 Toast.makeText(this, "bt33333333333", Toast.LENGTH_LONG).show(); 54 break; 55 default: 56 break; 57 } 58 } 59 60 }

网友评论
<