0

I am using DrawerToggle with toolbar in my project. I have a requirement to make drawer toggle in active (i.e it should not open or close on click or swipe). But I am completely struct how to achieve the things by making the toggle event standstill. I know that my question is quite different but my requirement is to control dynamically on a runtime to control the property of drawertoggle.

I am also posting piece of code I am using for drawertoggle in my project for your reference

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

        findViews();


        createFragments ();

        materialColorNames = getResources ().getStringArray(R.array.color_names);

        drawerAdpater = new DrawerAdapter(this,materialColorNames);
        mDrawerList.setAdapter(drawerAdpater);



        if (toolbar != null) {
            changeTitleText ("Droid");

            toolbar.setTitleTextColor (getResources ().getColor (R.color.droid_white));

            setSupportActionBar (toolbar);
        }
        initDrawer();


        updateFragment (0);
        mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
    }


    @Override
    protected void onResume () {
        super.onResume ();



    }

    private void changeTitleText (CharSequence title) {
        toolbar.setTitle(title);
    }

    private void createFragments () {

        myProjectsFragment = new MyProjectsFragment();

    }

    private void findViews() {
        mDrawerList = (ListView) findViewById(R.id.left_drawer);
        toolbar = (Toolbar) findViewById(R.id.toolbar);

        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);


    }

    private void initDrawer() {

        drawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close) {

            @Override
            public void onDrawerClosed(View drawerView) {
                super.onDrawerClosed(drawerView);

            }

            @Override
            public void onDrawerOpened(View drawerView) {
                super.onDrawerOpened(drawerView);
//                mDrawerLayout.closeDrawer(mDrawerList);



            }
        };
        mDrawerLayout.setDrawerListener(drawerToggle);
    }

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        drawerToggle.syncState();
    }

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



private void updateFragment(int position) {

        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();

        switch (position) {

            case 0:
                ft.replace(R.id.content_frame, myProjectsFragment);
                break;
}

Kindly please help me with this solution. I am seraching this to be done for the long time. Thanks in advance. Please let me know through comments if my question is not clear.

4

1 回答 1

1

在您的onCreate()后抽屉布局和列表中找到调用:

mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, mDrawerList);
drawerToggle.setDrawerIndicatorEnabled(false);

Javadoc

public void setDrawerLockMode (int lockMode, View drawerView)

启用或禁用与给定抽屉的交互。

这允许应用程序限制用户打开或关闭给定抽屉的能力。如果抽屉被锁定,DrawerLayout 仍会响应对 openDrawer(int)、closeDrawer(int) 和朋友的调用。

于 2015-04-26T11:42:38.520 回答