我的 activity
:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".activity.ShowUI">
<androidx.appcompat.widget.Toolbar
android:id="@+id/show_ui_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/AppTheme"
app:layout_constraintTop_toTopOf="parent"
app:titleTextColor="@android:color/white" />
<com.google.android.material.tabs.TabLayout
android:id="@+id/show_ui_tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?actionBarSize"
app:tabGravity="fill"
app:tabIndicatorColor="@android:color/black"
app:tabIndicatorHeight="2dp"
app:tabBackground="@color/colorPrimary"
app:tabMode="fixed">
</com.google.android.material.tabs.TabLayout>
<androidx.viewpager.widget.ViewPager
android:id="@+id/show_ui_viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent">
</androidx.viewpager.widget.ViewPager>
</LinearLayout>
我找不到问题出在哪里。谢谢你!我想知道如何删除这行白色填充物:我的活动:我的活动
只要删除 android:minHeight="?actionBarSize"
从TabLayout
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".activity.ShowUI">
<androidx.appcompat.widget.Toolbar
android:id="@+id/show_ui_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/AppTheme"
app:layout_constraintTop_toTopOf="parent"
app:titleTextColor="@android:color/white" />
<com.google.android.material.tabs.TabLayout
android:id="@+id/show_ui_tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabGravity="fill"
app:tabIndicatorColor="@android:color/black"
app:tabIndicatorHeight="2dp"
app:tabBackground="@color/colorPrimary"
app:tabMode="fixed">
</com.google.android.material.tabs.TabLayout>
<androidx.viewpager.widget.ViewPager
android:id="@+id/show_ui_viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent">
</androidx.viewpager.widget.ViewPager>
</LinearLayout>
或者,你也可以将TabLayout的高度设置为 "actionBarSize",而不是像这样指定为minHeight。
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".activity.ShowUI">
<androidx.appcompat.widget.Toolbar
android:id="@+id/show_ui_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/AppTheme"
app:layout_constraintTop_toTopOf="parent"
app:titleTextColor="@android:color/white" />
<com.google.android.material.tabs.TabLayout
android:id="@+id/show_ui_tabLayout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:tabGravity="fill"
app:tabIndicatorColor="@android:color/black"
app:tabIndicatorHeight="2dp"
app:tabBackground="@color/colorPrimary"
app:tabMode="fixed">
</com.google.android.material.tabs.TabLayout>
<androidx.viewpager.widget.ViewPager
android:id="@+id/show_ui_viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent">
</androidx.viewpager.widget.ViewPager>
</LinearLayout>