พอดีเห็นช่วงนี้แอพไหนๆ ก็มี Drawer กันหมด อย่าง Gmail, YouTube, Facebook ก็เลยอยากทำบ้าง


พอ search google ปุ๊ปก็เจอ SlidingDrawer เลย ก็เลยนั่งอ่านอยู่ตั้งนาน ไปเจอว่ามัน deprecated ไปละ link
This class was deprecated in API level 17. This class is not supported anymore. It is recommended you base your own implementation on the source code for the Android Open Source Project if you must use it in your application.API ที่ต้องใช้ก็คือ DrawerLayout
ก็ทำตามตัวอย่างเลย แต่ผลออกมาไม่เห็นเหมือนอย่างที่ต้องการ คือ 1.
- actionBar ข้างบนมันไม่เลื่อนไปด้านขวาตาม drawer 2.
- drawer มันทับ content ด้านล่าง ถ้าตามแอพอื่นมันต้องเลื่อนไปด้านขวาด้วยเหมือนกันซิ
1. ต้อง hide actionbar แล้วก็สร้าง view ที่หน้าตาเหมือน actionbar ขึ้นมาเอง
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); getActionBar().hide(); }
2. ต้องใช้ DrawerListener อ้อแล้วก็เซ็ท scrim color เป็น 0 ด้วยจะได้ transparent เหมือนแอพอื่น
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_drawer); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerLayout.setScrimColor(0); mDrawerLayout.setDrawerListener(this); } public void onDrawerSlide(View drawerView, float slideOffset) { contentFrame.setX(slideOffset * mDrawerList.getMeasuredWidth()); }
ก็จะได้ผลลัพธ์ที่ต้องการ