I have been able to show the "hamburger" icon on my toolbar, but when I click on it, nothing is happening... The only way to bring my drawer is to slide from the left..
Here's my code:
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mToolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
mDrayerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrayerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
mDrawerList.setAdapter(new ArrayAdapter<>(this, R.layout.drawer_list_item, test));
mDrawerList.setOnItemClickListener(new DrawerListClickListener());
mDrawerToggle = new ActionBarDrawerToggle(this, mDrayerLayout, R.string.navigation_drawer_open, R.string.navigation_drawer_close){
public void onDrawerClosed(View view){
super.onDrawerClosed(view);
getSupportActionBar().setTitle("Close");
invalidateOptionsMenu();
mDrawerToggle.syncState();
}
public void onDrawerOpened(View drawerView){
super.onDrawerClosed(drawerView);
getSupportActionBar().setTitle("Open");
invalidateOptionsMenu();
mDrawerToggle.syncState();
}
};
mDrawerToggle.syncState();
mDrayerLayout.setDrawerListener(mDrawerToggle);
}
Here's my xml file. I don't think it will help but who knows.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Toolbar -->
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="#style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"/>
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/my_toolbar">
<!-- The main content view -->
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<ListView android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
</android.support.v4.widget.DrawerLayout>
Thanks!
When using the four-parameter constructor for ActionBarDrawerToggle, you need to override the Activity's onOptionsItemSelected() method, and call the toggle's corresponding method to trigger the drawer opening and closing.
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if(mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
...
return super.onOptionsItemSelected(item);
}
Related
My Activity code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Overview overview = new Overview();
Intent intent = getIntent();
user.setUserName(intent.getStringExtra("Username"));
setContentView(R.layout.activity_second);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.mycontainer, overview)
.commit();
}
Toolbar toolbar = (Toolbar) findViewById(R.id.my_toolbar);
DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
toggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawerLayout.addDrawerListener(toggle);
toggle.syncState();
NavigationView navView = (NavigationView) findViewById(R.id.navview);
navView.setNavigationItemSelectedListener(this);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.actionbar_menu, menu);
return true;
}
// Toggle function for the navigational drawer
#Override
public boolean onOptionsItemSelected(MenuItem item){
if(toggle.onOptionsItemSelected(item)){
return true;
}
return super.onOptionsItemSelected(item);
}
After adding this line:
getSupportActionBar().setDisplayShowTitleEnabled(false);
My drawer dissapeared. So all I have left is my actionbar_menu.
My XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".SecondActivity.SecondActivity"
android:id="#+id/drawer_layout">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:id="#+id/mycontainer"
>
<android.support.v7.widget.Toolbar
android:id="#+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="#style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
/>
</LinearLayout>
<android.support.design.widget.NavigationView
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginTop="?attr/actionBarSize"
android:id="#+id/navview"
app:menu="#menu/nav_menu"
app:headerLayout="#layout/nav_header"
>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
So basically, how do I get both my actionbar, my DrawerLayout and a custom title to work? I have to disable the showTitleEnabled to set a custom title, but it makes my menu dissapear. So how do I fix this?
You can create a custom toolbar layout and include it in your XML instead of <android.support.v7.widget.Toolbar>
and in your custom toolbar layout put a TextView.
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Was missing. This fixes it
I am using android default navigation drawer and i want that same layout for all the activities i tried searching on internet i got some ideas for customized drawer but not on android studio default drawer. Kindly help me.
navigation drawer.class :
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton)
findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action",
Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open,
R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView)
findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
app_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="#layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
app_bar_main.xml :
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.spykid.navig.navig_sample.Main2Activity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_main" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
android:src="#android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout>
Here in app_bar_main layout i would like to change that
include layout="#layout/content_main" with my activity or fragment so that i can have the same layout.
Thanks in advance.
Create an Activity containing only NavigationDrawer and after that OnItemSelected from NavigationDrawer call every activity you want. Then NavigationDrawer will be available in all the activities.
The other solution is create MainActivity with NavigationDrawer and create other Fragments instead of Activities. Call those Fragmnets OnItemSelected from NavigationDrawer. There are alot of example available there.
Edit
In your activity where you have defined navigationDrawer, do the following. And instead of creating new activities for next layouts, create fragments and call them on OnItemSelected on navigationDrawer like below:
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
// This method will trigger on item Click of navigation menu
#Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
//Checking if the item is in checked state or not, if not make it in checked state
if (menuItem.isChecked()) menuItem.setChecked(false);
else menuItem.setChecked(true);
//Closing drawer on item click
drawerLayout.closeDrawers();
//Check to see which item was being clicked and perform appropriate action
switch (menuItem.getItemId()) {
//Replacing the main content with ContentFragment Which is our Inbox View;
case R.id.drawer_home:
Intent intent=new Intent(HomeActivity.this, HomeActivity.class);
startActivity(intent);
overridePendingTransition(0, 0);
finish();
return true;
// For rest of the options we just show a toast on click
case R.id.drawer_artist:
android.support.v4.app.FragmentManager fragmentManager=getSupportFragmentManager();
android.support.v4.app.FragmentTransaction fragmentTransaction=fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.content_frame, new ArtistsFragment());
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
return true;
default:
Toast.makeText(getApplicationContext(), "Somethings Wrong", Toast.LENGTH_SHORT).show();
return true;
}
}
});
Fragment code will be like:
public class ArtistsFragment extends Fragment {
public ArtistsFragment() {
// Required empty public constructor
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootview= inflater.inflate(R.layout.fragment_artists, container, false);
return rootview;
}}
activity_main.xml:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:elevation="4dp"
android:layout_height="fill_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<include
android:id="#+id/tool_bar"
layout="#layout/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
/>
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/home">
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
</LinearLayout>
</FrameLayout>
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="#+id/navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
android:background="#drawable/bg_all"
app:itemIconTint="#android:color/white"
app:itemTextColor="#android:color/white"
app:theme="#style/list_item_appearance"
app:menu="#menu/drawer_menu" >
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
This is what my code looks like, my activity extends Activity. I am having trouble getting the Hamburger menu icon as i get back arrow menu icon. which i dont want.
code in mainactivity:
ActionBar actionBar = getActionBar();
actionBar.setCustomView(R.layout.action_bar);
actionBar.setDisplayShowCustomEnabled(true);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
menu_list = new ArrayAdapter<String>(this, R.layout.drawer_list,
getResources().getStringArray(R.array.menu_options));
mDrawerList.setAdapter(menu_list);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,R.drawable.ic_drawer ,R.string.app_name, R.string.app_name);
mDrawerLayout.setDrawerListener(mDrawerToggle);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
code in action_bar.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="vertical"
android:background="#29ABE2" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:gravity="center_vertical"
android:textColor="#FFF"
android:textSize="25dp"
android:text="DataVision" />
</LinearLayout>
additional methods:
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Pass the event to ActionBarDrawerToggle
// If it returns true, then it has handled
// the nav drawer indicator touch event
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
// Handle your other action bar items...
return super.onOptionsItemSelected(item);
}
#Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
mDrawerToggle.syncState();
}
You need to wrap your existing LinearLayout in a DrawerLayout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
then your LinearLayout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="vertical"
android:background="#29ABE2" >
<TextView
android:id="#+id/textView1"
etc.
...
</LinearLayout>
then the drawer:
<ListView android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
</android.support.v4.widget.DrawerLayout>
see also: https://developer.android.com/training/implementing-navigation/nav-drawer.html
I want to create a navigation drawer that contains tabs in android, but I could not do anything. I want to add tabs (categories, favorites) to the navigation drawer.Is it posible?
(eg. ios)
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer,
R.string.app_name, R.string.app_name ){
public void onDrawerClosed(View view) {
// calling onPrepareOptionsMenu() to show action bar icons
// invalidateOptionsMenu();
}
public void onDrawerOpened(View drawerView) {
// calling onPrepareOptionsMenu() to hide action bar icons
//invalidateOptionsMenu();
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN);
tabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
tabHost.setup(getApplicationContext(), getSupportFragmentManager(), android.R.id.tabcontent );
tabHost.addTab(tabHost.newTabSpec("surec").setIndicator("Süreç listesi"), SurecListesiFragment.class, null);
tabHost.addTab(tabHost.newTabSpec("bolum").setIndicator("Bölüm listesi"), PhotosFragment.class, null);
I cannot switch between tabs. And I cannot use any widgets on tab content. (listview, button, etc.. )
(EDIT : solution)
(linearlayout : slider menu layout)
linearLayout.bringToFront();
linearLayout.requestLayout();
I did it just yesterday.
This is my layout for main activity with drawer:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- Main layout -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/app_background"
android:orientation="vertical" >
<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="#layout/layout_location_spinners_campaigns" />
<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="#layout/layout_campaignslistview" />
</LinearLayout>
<!-- Slider menu -->
<LinearLayout
android:id="#+id/preferencesDrawer"
android:layout_width="290dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="#color/app_background"
android:orientation="vertical" >
<android.support.v4.app.FragmentTabHost
android:id="#android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:orientation="horizontal" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0" />
<FrameLayout
android:id="#+id/realtabcontent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
The method to display the tabs:
FragmentTabHost tabhost;
void buildTabs() {
tabhost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
tabhost.addTab(tabhost.newTabSpec("locations").setIndicator(getString(R.string.locations)), FragmentPreferencesLocations.class, null);
tabhost.addTab(tabhost.newTabSpec("categories").setIndicator(getString(R.string.categories)),FragmentPreferencesCategories.class, null);
}
Besides that you need code to display the drawer and customize your tabs...
EDIT:
I initialize drawer with this method (invoke it at onCreate):
ActionBarDrawerToggle drawerToggle;
LinearLayout preferencesDrawer;
FragmentTabHost tabhost;
...
void initDrawer() {
drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.ic_launcher, R.string.app_name,
R.string.app_name) {
public void onDrawerClosed(View drawerView) {
getSupportActionBar().setTitle(getString(R.string.app_name));
// calling onPrepareOptionsMenu() to show action bar icons
invalidateOptionsMenu();
drawerClosed(drawerView);
}
public void onDrawerOpened(View drawerView) {
getSupportActionBar().setTitle(getString(R.string.preferences));
// calling onPrepareOptionsMenu() to hide action bar icons
invalidateOptionsMenu();
}
};
drawerLayout.setDrawerListener(drawerToggle);
}
// Invoked by action bar button
void clickFilterCategories() {
toggleDrawer(preferencesDrawer);
}
void toggleDrawer(View drawer) {
if (drawerLayout.isDrawerOpen(drawer)) {
closeDrawer(drawer);
} else {
openDrawer(drawer);
}
}
void openDrawer(View toOpen) {
drawerLayout.openDrawer(toOpen);
}
void closeDrawer(View toClose) {
drawerLayout.closeDrawer(toClose);
}
I'm currently trying to implement a Navigation Drawer into my Application. For that i want the Drawer to be opened when the activity is started. This is my onCreate:
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_master);
isInLandscapeMode = getResources().getBoolean(R.bool.isInLandscape);
if (!isInLandscapeMode)
{
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.ic_drawer, R.string.date, R.string.applicationName)
{
/**
* Called when a drawer has settled in a completely closed
* state.
*/
public void onDrawerClosed(View view)
{
super.onDrawerClosed(view);
}
/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View drawerView)
{
super.onDrawerOpened(drawerView);
drawerView.bringToFront();
drawerView.requestLayout();
}
};
// Set the drawer toggle as the DrawerListener
drawerLayout.setDrawerListener(drawerToggle);
drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
}
drawerLayout.openDrawer(Gravity.START);
}
The Drawer is opening as it should but if i try to click one of my list entries it closes. If I open it manually afterwards everything is working perfectly. Do I have to set the focus on my drawerLayout somehow? I have tried several things but nothing seems to work.
UPDATE
Finally found my error:
I had the following code in my layout xml file:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/list_container"
android:layout_width="320dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#f1f1f1"
android:orientation="horizontal" >
</LinearLayout>
<FrameLayout
android:id="#+id/detail_container"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal" >
</FrameLayout>
</android.support.v4.widget.DrawerLayout>
</FrameLayout>
The main content view(detail_container) must be the first child in the navigation drawer thought. So i changed it to this:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:id="#+id/detail_container"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal" >
</FrameLayout>
<LinearLayout
android:id="#+id/list_container"
android:layout_width="320dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#f1f1f1"
android:orientation="horizontal" >
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
</FrameLayout>
And it worked.
Use drawer.openDrawer(Gravity.LEFT);
After you find your drawer layout and Data(list or expandable list) then put
drawerLayout.openDrawer("Name of Data Contained By Drawer");