我試圖與TabLayout摺疊式工具如下摺疊式工具與TabLayout沒有顯示工具欄
https://i.stack.imgur.com/76m5h.gif
,你可以看到工具欄不顯示在所有。 在java中我設置工具欄的動作條使用
setSupportActionBar(toolbar);
我嘗試過很多這樣的答案和其他網站,但沒能解決我的問題。
下面是我使用的xml。
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsingToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/bg_main"
android:orientation="vertical">
<com.gigamole.navigationtabstrip.NavigationTabStrip
android:id="@+id/nts_strip"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_gravity="top"
android:background="@color/colorPrimary"
app:layout_collapseMode="parallax"
app:nts_active_color="@color/white"
app:nts_animation_duration="300"
app:nts_color="@color/white"
app:nts_corners_radius="1.5dp"
app:nts_inactive_color="@color/white_transparent"
app:nts_titles="@array/nts_titles" />
<android.support.v4.view.ViewPager
android:id="@+id/pager_photos"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@color/white_transparent" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
這裏是styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
請讓我知道你需要什麼。
您是否初始化了java端的'Toolbar'?你的Styles.xml代碼是什麼? – Mohsen
這很奇怪,你可以嘗試'Layout'沒有'NavigationTabStrip'並且沒有'LinearLayout',只是一個'ViewPager'並且讓我知道? – Mohsen
@Mohsen的問題是工具欄不可見爲什麼你建議刪除線性佈局?你能提供一個有效的理由嗎? – SaravInfern