Навигация в отворена кутия само в родителския фрагмент

Примерен код

0
0

A clean way to do this is to create an interface that the Activity implements, through which the Fragment can call a method local to the Activity that handles the drawer lock and toggle button states. For example:

public interface DrawerLocker {
    public void setDrawerEnabled(boolean enabled);
}
In the Activity's interface method, we simply figure the lock mode constant for the DrawerLayout#setDrawerLockMode() call, and call setDrawerIndicatorEnabled() on the ActionBarDrawerToggle.

public class MainActivity extends Activity implements DrawerLocker {

    public void setDrawerEnabled(boolean enabled) {
        int lockMode = enabled ? DrawerLayout.LOCK_MODE_UNLOCKED :
                                 DrawerLayout.LOCK_MODE_LOCKED_CLOSED;
        drawer.setDrawerLockMode(lockMode);
        toggle.setDrawerIndicatorEnabled(enabled);
    }

    ...
}
In the Fragment, we merely need to cast the hosting Activity to the interface, and call the setDrawerEnabled() method accordingly. For example, to lock the drawer shut:

((DrawerLocker) getActivity()).setDrawerEnabled(false);

Подобни страници

Подобни страници с примери

На други езици

Тази страница на други езици

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Íslensk
..................................................................................................................