【发布时间】:2015-10-25 16:08:28
【问题描述】:
所以我正在为 Android 创建一个 Material Design 应用。我正在使用新的工具栏而不是使用操作栏。在一项活动中,我想在工具栏下方显示选项卡。这适用于纵向和横向模式,但在横向模式下,选项卡居中并且不会覆盖视图的整个宽度。
这是设计使然还是有什么我需要知道的?
这是我的活动的布局:
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:height="?attr/actionBarSize"
android:background="@color/primary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:titleTextAppearance="@style/ToolbarTitle"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/toolbar_tabs"
android:height="?attr/actionBarSize"
android:background="@color/primary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways" />
</android.support.design.widget.AppBarLayout>
下面的代码在onCreate中初始化这个:
// Set up the toolbar
this.setSupportActionBar(mToolbar);
ActionBar ab = this.getSupportActionBar();
if (ab != null)
{
ab.setDisplayHomeAsUpEnabled(true);
ab.setHomeButtonEnabled(true);
ab.setDisplayShowTitleEnabled(true);
}
// Set up the pager and tabs from the pager
mTabViewPager.setAdapter(mTabPagerAdapter);
mTabLayout.setupWithViewPager(mTabViewPager);
mTabPagerAdapter 是一个寻呼机适配器,用于保存文档中的选项卡显示的页面。
【问题讨论】:
-
为什么投反对票?
标签: android material-design android-toolbar