Tabs in TabLayout not filling up entire ActionBar(TabLayout 中的选项卡没有填满整个 ActionBar)
问题描述
我正在使用 TabLayout
和 ViewPager
按照指南 .
GRAVITY_CENTER
用于在 TabLayout 的中心布置选项卡的重力.
GRAVITY_FILL
用于尽可能多地填充 TabLayout 的重力.
MODE_FIXED
固定选项卡同时显示所有选项卡,最适合用于受益于选项卡之间快速旋转的内容.
MODE_SCROLLABLE
可滚动标签在任何给定时刻显示标签的子集,并且可以包含更长的标签标签和更多的标签.
在您的代码或布局 xml 中设置它.
app:tabGravity="center"应用程序:tabMode =固定"
或
tabLayout.setTabGravity(TabLayout.GRAVITY_CENTER);tabLayout.setTabMode(TabLayout.MODE_FIXED);
一般情况下,使用像blow这样的代码可以不用设置tabGravity
和tabMode
.
I am using a TabLayout
and ViewPager
to display ActionBar tabs
following the guide Google Play Style Tabs using TabLayout, however my tabs are squished to the left side of the ActionBar, shown below:
And I would like them to take up the whole bar with equal widths. I've made only a few minor changes to the guide:
In activity_main.xml a style was created to show the ActionBar:
<android.support.design.widget.TabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/AppTheme"
app:tabMode="scrollable" />
Here is the styles.xml code:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowActionBar">true</item>
<item name="tabIndicatorColor">#ffff0030</item>
</style>
Also, my MainActivity
now extends AppCompatActivity
instead of a FragmentActivity
.
You can refer to the TabLayout.
GRAVITY_CENTER
Gravity used to lay out the tabs in the center of the TabLayout.
GRAVITY_FILL
Gravity used to fill the TabLayout as much as possible.
MODE_FIXED
Fixed tabs display all tabs concurrently and are best used with content that benefits from quick pivots between tabs.
MODE_SCROLLABLE
Scrollable tabs display a subset of tabs at any given moment, and can contain longer tab labels and a larger number of tabs.
Set this in your code or your layout xml.
app:tabGravity="center"
app:tabMode="fixed"
or
tabLayout.setTabGravity(TabLayout.GRAVITY_CENTER);
tabLayout.setTabMode(TabLayout.MODE_FIXED);
Generally, using the code like blow can work without setting tabGravity
and tabMode
.
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_scrollFlags="scroll|enterAlways" />
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
这篇关于TabLayout 中的选项卡没有填满整个 ActionBar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:TabLayout 中的选项卡没有填满整个 ActionBar
基础教程推荐
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 降序排序:Java Map 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01