打开抽屉时,NavigationDrawer图标不会向左滑动?

时间:2015-06-24 13:13:59

标签: java android

如果我通过从左向右滑动或单击App-Icon打开NavigationDrawer,则三个水平条不会变小(幻灯片动画不起作用)。

我已经阅读了很多关于NavigationDrawer和显示图标所必需的方法,在我看来,我做的一切都是正确的。 希望有人可以帮助我!

package com.example.projektmarktplatz;
import android.app.ActionBar;
import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends Activity implements OnItemClickListener{

    private DrawerLayout drawerLayout;
    private ListView listViewNavigation;
    private ListView listViewFilter;
    private String[] filters;
    private ActionBarDrawerToggle drawerListener;
    private NavDrawerAdapter NavDrawerAdapter;



    @SuppressWarnings("deprecation")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //NavigationDrawer und ListViews für Navigation und Filter setzen
        drawerLayout =(DrawerLayout) findViewById(R.id.drawerLayout);
        NavDrawerAdapter = new NavDrawerAdapter(this);
        listViewNavigation = (ListView) findViewById(R.id.drawerList);
        listViewFilter = (ListView) findViewById(R.id.filterList);
        listViewNavigation.setAdapter(NavDrawerAdapter);
        filters=getResources().getStringArray(R.array.beispielFilter);
        listViewFilter.setAdapter(new ArrayAdapter<>(this, android.R.layout.select_dialog_multichoice, filters));

        //OnClickItemListener setzen
        listViewNavigation.setOnItemClickListener(this);

        //DrawerListener um Öffnen/Schließen des Drawers wahrzunehmen
        drawerListener=new ActionBarDrawerToggle(this, drawerLayout, R.drawable.ic_drawer,
                R.string.drawer_open, R.string.drawer_close){
            public void onDrawerClosed(View drawerView){
                super.onDrawerClosed(drawerView);
            }
            public void onDrawerOpened(View drawerView){
                super.onDrawerClosed(drawerView);
            }
        };
        drawerLayout.setDrawerListener(drawerListener);
        getActionBar().setHomeButtonEnabled(true);
        getActionBar().setDisplayHomeAsUpEnabled(true);
    }

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onPostCreate(savedInstanceState);
        drawerListener.syncState();
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        drawerListener.onConfigurationChanged(newConfig);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        selectItem(position);


    }


    public void selectItem(int position) {
        listViewNavigation.setItemChecked(position,true);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        //Durch klick auf AppIcon wird  NavigationDrawer geöffnet
        if (drawerListener.onOptionsItemSelected(item)) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

0 个答案:

没有答案