Android 为什么滑动菜单栏的点击不来?

Android 为什么滑动菜单栏的点击不来?,android,android-listview,slidingmenu,slidingdrawer,Android,Android Listview,Slidingmenu,Slidingdrawer,在下面的代码中,滑动抽屉菜单栏即将出现,但当我单击菜单项时,什么也没有发生。我期待着在按钮菜单的按钮单击时打开滑动抽屉。我不知道如何在按钮单击时打开滑动抽屉。当我单击抽屉时,它消失在左侧。如果我点击菜单项(主页),它应该会打开Mainactivity.class。我还没有为此编写代码 package com.bar.start; import com.bar.barapp.R; import android.app.Activity; import android.app.Fragment

在下面的代码中,滑动抽屉菜单栏即将出现,但当我单击菜单项时,什么也没有发生。我期待着在按钮菜单的按钮单击时打开滑动抽屉。我不知道如何在按钮单击时打开滑动抽屉。当我单击抽屉时,它消失在左侧。如果我点击菜单项(主页),它应该会打开Mainactivity.class。我还没有为此编写代码

 package com.bar.start;

import com.bar.barapp.R;

import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends Activity {

    Button loc,buttonmenu;

     String[] menu;
     DrawerLayout dLayout;
     ListView dList;
     ArrayAdapter<String> adapter;


    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
         //this.requestWindowFeature(Window.FEATURE_NO_TITLE);

         setContentView(R.layout.homescreen);

        // getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebar);


         menu = new String[]{"Home","Android","Windows","Linux","Raspberry Pi","WordPress","Videos","Contact Us"};
            dLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
            dList = (ListView) findViewById(R.id.left_drawer);

            adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,menu);

            dList.setAdapter(adapter);
            dList.setSelector(android.R.color.holo_blue_dark);

            dList.setOnItemClickListener(new OnItemClickListener(){

                @Override
                public void onItemClick(AdapterView<?> arg0, View v, int position, long id) {

                    dLayout.closeDrawers();                 
                    Bundle args = new Bundle();
                    args.putString("Menu", menu[position]);
                    Fragment detail = new Menu_view();
                    detail.setArguments(args);
                    FragmentManager fragmentManager = getFragmentManager();         
                    fragmentManager.beginTransaction().replace(R.id.content_frame, detail).commit();


                }

            });



        loc=(Button)findViewById(R.id.location);

        loc.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent in =new Intent(MainActivity.this,LocationActivity.class);
                startActivity(in);

            }
        });


        buttonmenu=(Button)findViewById(R.id.menubutton);
        buttonmenu.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                Toast.makeText(getApplicationContext(), "hello", Toast.LENGTH_LONG).show();

            }
        });

    }



}
菜单\u detail.xml

    <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/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <ListView android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"

        android:dividerHeight="0dp"
        android:background="#800000"/>

    <RelativeLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" 
    android:background="@drawable/startupscreen">

    <ScrollView
            android:id="@+id/scrollView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

        <LinearLayout
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:orientation="vertical"  >
    <LinearLayout
        android:id="@+id/menulayout"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:weightSum="1"
         android:paddingTop="30dp"
         android:orientation="horizontal">

        <Button 
            android:id="@+id/menubutton"
            android:layout_width="0dp"
            android:layout_height="40dp"
            android:layout_weight="0.3"
            android:text="@string/menu"
            /> 

        <TextView
        android:layout_weight="0.2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"/>

         <TextView
        android:layout_weight="0.2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="@string/search"
        android:textSize="14sp"
        android:textColor="@color/black"/>

        <EditText
          android:layout_weight="0.3"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:paddingRight="10dp"
        android:focusable="false"
        android:focusableInTouchMode="true"/>

    </LinearLayout>

         <ExpandableListView
             android:layout_below="@+id/menulayout"
                android:id="@+id/searchres"
                android:layout_width="fill_parent"
                android:layout_height="350dp"
                android:clipChildren="true"
                android:groupIndicator="@null"
                android:background="@color/gray"
                 />


    <LinearLayout
        android:id="@+id/buttons"
         android:layout_width="match_parent"
         android:layout_height="50dp"
         android:weightSum="1.5"
         android:orientation="horizontal"
         android:layout_below="@+id/searchres">

         <Button 
            android:id="@+id/location" 
            android:layout_width="0dp"
            android:layout_height="40dp"
            android:layout_weight="0.5"
            android:text="@string/location"
            android:background="@drawable/btn_image"
            /> 

         <Button 
            android:layout_width="0dp"
            android:layout_height="40dp"
            android:layout_weight="0.5"
            android:visibility="invisible"
            /> 

         <Button 
            android:id="@+id/barype"
            android:layout_width="0dp"
            android:layout_height="40dp"
            android:layout_weight="0.5"
            android:text="@string/bartype"
             android:background="@drawable/btn_image"
            /> 

         </LinearLayout>

    <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:orientation="horizontal"
          android:gravity="center_vertical|center_horizontal"
          android:layout_below="@+id/buttons">

          <Button 
            android:id="@+id/joggle"  
            android:layout_width="wrap_content"
            android:layout_height="40dp"
            android:background="@drawable/btn_image"
            android:text="@string/joggle"
            /> 

        </LinearLayout>

</LinearLayout>

    </ScrollView>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:gravity="center"
    android:background="#5ba4e5"
    android:layout_height="match_parent">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="40px"
        android:textColor="#000000"
        android:layout_gravity="center"
        android:id="@+id/detail"/>

</LinearLayout>


info@Ajeet…即使这个例子不起作用,我也用这个例子作为参考。好的..我的错。那么你得到的是一个空白抽屉吗?@Ajeet..在做示例时,一个空白活动。当我运行我的代码(有疑问)时,当我拖动我的左屏幕时,一个空白的抽屉出现了
    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:gravity="center"
    android:background="#5ba4e5"
    android:layout_height="match_parent">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="40px"
        android:textColor="#000000"
        android:layout_gravity="center"
        android:id="@+id/detail"/>

</LinearLayout>