我有一個ViewPager其中網頁包含圖表視圖,其反應的滑動動作。由於這個原因,我採取了通過從屏幕邊緣滑動來改變頁面。但是這給我帶來的問題是,這也是打開NavigationDrawer的手勢。如何防止NavigationDrawer從手勢被打開,但是從漢堡包圖標允許支持設計庫23.1.1.1
到現在爲止我用下面的代碼來實現這一目標:
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(GetLayoutId());
Toolbar = FindViewById<Toolbar>(Resource.Id.toolbar);
if (Toolbar != null)
{
// set this flag so the colors colorPrimaryDark and android:statusBarColor have an effect
// setting android:statusBarColor to transparent causes the drawer to be dran underneath a translucent status bar
Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
// make the toolbar the replacement of the action bar
SetSupportActionBar(Toolbar);
}
// add the hamburger icon
m_DrawerLayout = FindViewById<DrawerLayout>(Resource.Id.drawer_layout);
var actionBarDrawerToggle = new ActionBarDrawerToggle(this, m_DrawerLayout, Toolbar, Resource.String.empty, Resource.String.empty);
m_DrawerLayout.AddDrawerListener(actionBarDrawerToggle);
// make sure the drawer can't be opened by swiping, to do this we set the lock mode to closed
// but if we just do this, it can't be closed by swiping either, so set the lock mode to unlocked when the drawer is opened, and locked again when it's closed
m_DrawerLayout.DrawerOpened += (object sender, DrawerLayout.DrawerOpenedEventArgs e) =>
{
m_DrawerLayout.SetDrawerLockMode(DrawerLayout.LockModeUnlocked);
};
m_DrawerLayout.DrawerClosed += (object sender, DrawerLayout.DrawerClosedEventArgs e) =>
{
m_DrawerLayout.SetDrawerLockMode(DrawerLayout.LockModeLockedClosed);
};
m_DrawerLayout.SetDrawerLockMode(DrawerLayout.LockModeLockedClosed);
//calling sync state is necessay or else the hamburger icon wont show up
actionBarDrawerToggle.SyncState();
}
它的工作如預期,直到我更新到Android支持設計庫23.1.1.1,現在設置爲關閉,也可以防止鎖定模式通過點擊漢堡圖標打開菜單。
一個不規範的行爲:) – jaibatrik
可能是你需要創建'DrawerLayout'延伸的定製'View'。 – jaibatrik
如果確實是導致這種情況的更新,那麼聽起來就像是一場混戰。你可能會想恢復到以前的庫版本,直到他們修復它,或者說現在是預期的行爲,這不會很有趣,因爲這將需要一個不必要的複雜的解決方法來獲得舊的行爲。 –