多个活动的导航抽屉不起作用

时间:2014-10-06 06:43:35

标签: java android android-fragments navigation-drawer android-menu

我试图为多个活动获取相同的导航抽屉。目前,我有一个BaseActivity,它包含导航抽屉和一个扩展BaseActivity类的MainActivity。当我首先运行BaseActivity时它工作正常但是如果我首先运行MainActivity(这是我想要做的),当我从左向右滑动屏幕时,导航抽屉不起作用。我现在一直坚持这一点,似乎无法弄清楚我错过了什么。任何帮助将不胜感激。

HomeActivity Class


public class HomeActivity extends BaseActivity {

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


    }
}

BaseActivity Class


public class BaseActivity extends ActionBarActivity {

    private String[] menuList;
    private DrawerLayout drawerLayout;
    private ListView listView;
    private ActionBarDrawerToggle drawerToggle;
    private CharSequence drawerTitle;
    private CharSequence title;

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

        // Initialize drawer's list of items. Get the array for the list
        menuList = getResources().getStringArray(R.array.menuItems);

        // Get the drawers layout
        drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        // Get the list view
        listView = (ListView) findViewById(R.id.list_view);

        // Creating an ArrayAdapter to add items to the listview listView
        listView.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1,
                menuList));

        // Set listener for the list item clicks
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView adapterView, View view, int i, long l) {

            }
        });
    }

activity_base.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">

    <!-- The main content view -->
    <FrameLayout
        android:id="@+id/frame_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <!-- The navigation drawer -->
    <ListView
        android:id="@+id/list_view"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="10dp" />

</android.support.v4.widget.DrawerLayout>

0 个答案:

没有答案