我想要这个效果。选项卡在工具栏中,而不是在工具栏
下。我搜索了所有的网站,但找不到做那件事的方法。所有的文档都告诉我如何在工具栏下添加选项卡,但这不是我想要的
我刚刚想出了答案,它比我想象的要简单:
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<android.support.design.widget.TabLayout
android:id="@+id/main_tabs"
style="@style/MainTabLayout"
app:tabIndicatorHeight="0dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/home_toolbar"/>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
就是这样。这和你的设计不完全一样,但你想怎么改就怎么改。不要忘记在fragment或activity上设置工具栏:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);