31
A
回答
73
如果您的工具欄位於可能位於CoordinatorLayout內的AppBarLayout中,那麼應該這樣工作。
AppBarLayout appBarLayout = (AppBarLayout)findViewById(R.id.appBar);
appBarLayout.setExpanded(true, true);
或者將其摺疊
AppBarLayout appBarLayout = (AppBarLayout)findViewById(R.id.appBar);
appBarLayout.setExpanded(false, true);
這裏的定義是
setExpanded(boolean expanded, boolean animate)
注意到,這種方法可從支持庫的V23,這裏是一些documentation參考,關鍵要注意的是「與AppBarLayout的滾動一樣,此方法依賴於此佈局是CoordinatorLayout的一個直接子節點。「希望這有助於!
7
這是你在找什麼?
Toolbar toolbar = findViewById(R.id.toolbar); // or however you need to do it for your code
AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbar.getLayoutParams();
params.setScrollFlags(0); // clear all scroll flags
鏈接:How to enable/disable toolbar scrolling programmatically when using design support library
爲了隱藏工具欄你可以做這樣的事情:
toolbar.animate().translationY(-toolbar.getBottom()).setInterpolator(new AccelerateInterpolator()).start();
如果你想再次顯示它您撥打:
toolbar.animate().translationY(0).setInterpolator(new DecelerateInterpolator()).start();
0
我的問題與@Artem非常相似我嘗試了很多修復,但沒有一個爲我工作。 @當你使用AppBarLayout
時,Jraco11的回答是正確的。 @ johnrao07不適合我。但是當我們使用Toolbar
時,我發現了一個完美的解決方案。
要隱藏工具欄編程
if (toolbar.getParent() instanceof AppBarLayout){
((AppBarLayout)toolbar.getParent()).setExpanded(false,true);
}
要顯示的工具欄編程
if (toolbar.getParent() instanceof AppBarLayout){
((AppBarLayout)toolbar.getParent()).setExpanded(true,true);
參考原來的答案(由@android HHT答案): - programmatically-show-toolbar-after-hidden-by-scrolling-android-design-library
相關問題
- 1. 以編程方式隱藏工具欄
- 2. CoordinatorLayout:隱藏/顯示半可見工具欄?
- 3. 以編程方式顯示滾動隱藏後的工具欄(Android設計庫)
- 4. 在Angular4中以編程方式顯示/隱藏引導工具提示
- 5. 隱藏工具欄與CoordinatorLayout,但RecyclerView上的一個分段
- 6. 隱藏並顯示ckeditor工具欄
- 7. iPhone:隱藏/顯示工具欄
- 8. 如何顯示/隱藏PhotoSwipe工具欄
- 9. 如何以編程方式隱藏Android上的來電顯示
- 10. 機器人 - CoordinatorLayout/NestedScrollView /隱藏,顯示工具欄/問題與WebView中
- 11. CoordinatorLayout工具欄不隱藏在回收視圖滾動
- 12. 以編程方式構建工具欄
- 13. CoordinatorLayout不隱藏操作欄
- 14. 在報告中以編程方式隱藏/顯示行
- 15. 如何在Objective-C中以編程方式隱藏/顯示UITableView?
- 16. 如何在Android中以編程方式顯示/隱藏windowActionBar?
- 17. 以編程方式在drupal中顯示隱藏按鈕
- 18. 是否可以以編程方式顯示/隱藏SSRS PageNumber?
- 19. 隱藏和顯示kendo ui編輯器工具欄
- 20. 隱藏工具欄
- 21. 隱藏工具欄
- 22. 使用CoordinatorLayout從片段隱藏工具欄
- 23. 使用CoordinatorLayout時隱藏頂部和底部工具欄
- 24. 同時隱藏/顯示導航欄,工具欄和狀態欄
- 25. 以編程方式在iPhone鍵盤上對齊工具欄
- 26. 隱藏/顯示水龍頭上的工具欄
- 27. Compact Framework的底部工具欄上顯示/隱藏
- 28. 在工具欄上方顯示鍵盤?
- 29. 在工具欄上方顯示鍵盤?
- 30. 在Tabbar上方顯示工具欄
)驚人的回答,所有的工作,謝謝!!! – Artem