Iam嘗試在我的項目中爲片段和活動創建摺疊工具欄,但摺疊工具欄無法正常工作。請幫助我找到解決方案,正如iam new to android。 預先感謝您。如何在片段和活動中創建摺疊工具欄
0
A
回答
0
http://saulmm.github.io/mastering-coordinator
檢查。我發現學習使用CoordinatorLayout和摺疊佈局非常有用
0
首先,您需要創建一個AppBar佈局作爲主要父級。在這裏面添加一個CollapsingToolbarLayout。在CollapsingToolbarLayout裏面添加你想要的東西,在你的工具欄中,最後添加工具欄。
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways">
<!--This can be anything, here I've added a view pager inside collapsing toolbar-->
<android.support.v4.view.ViewPager
android:id="@+id/pager_introduction"
android:layout_width="match_parent"
android:layout_height="192dp"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax"
tools:listitem="@layout/pager_item" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
現在爲android部分實例化工具欄並進行設置。
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
在我來說,我已經添加了viewpager,一個單獨的適配器將不得不創建來填充viewpager。
相關問題
- 1. 可摺疊工具欄:設置在創建多少工具欄應該摺疊
- 2. 滾動片段應該摺疊工具欄
- 3. 摺疊工具欄和滾動
- 4. Android全屏對話框片段和摺疊工具欄問題
- 5. 如何摺疊摺疊工具欄時導航欄切換?
- 6. 摺疊工具欄默認摺疊
- 7. 如何創建彎曲的摺疊工具欄佈局?
- 8. 滾動時工具欄不能摺疊
- 9. 僅使用摺疊工具欄動畫
- 10. Android:創建片段工具欄
- 11. Parallax TabLayout與摺疊工具欄和imageview
- 12. ViewPager與Headerview和可摺疊工具欄
- 13. 新片段重疊工具欄
- 14. 自定義工具欄重疊片段
- 15. 片段重疊工具欄ViewPager
- 16. 如何顯示摺疊工具欄爲摺疊而不滾動android
- 17. 如何在摺疊工具欄佈局下添加viewpager和tablayout
- 18. 摺疊工具欄不會在依從佈局中滾動時摺疊
- 19. 從摺疊工具欄中不顯示工具欄
- 20. 摺疊工具欄中的工具欄佈局不被固定
- 21. 爲什麼摺疊工具欄標題在工具欄下?
- 22. Android Studio 1.5使用操作欄摺疊創建新活動
- 23. 摺疊工具欄 - 狀態欄下的工具欄
- 24. 在片段活動中添加工具欄
- 25. 如何在同一活動中使用摺疊工具欄和底部工作表視圖?
- 26. Android可摺疊工具欄不工作
- 27. 如何從工具欄中的片段活動設置圖像和文本android
- 28. 使用具有基於片段元素的佈局的摺疊工具欄
- 29. 如何在摺疊工具欄中實現輕掃圖像android
- 30. 如何在具有DrawerLayout,工具欄和ViewPager的佈局中摺疊工具欄與RecyclerView?
你試過這個解決方案嗎? http://stackoverflow.com/questions/30739806/coordinator-layout-with-toolbar-in-fragments-or-activity – AndroidBeginner