【问题标题】:TabLayout in the fragment is shadowed by activity's title bar片段中的 TabLayout 被活动的标题栏遮蔽
【发布时间】:2017-05-22 03:43:24
【问题描述】:

我有一个带有 4 个标签的 ActivityTabLayout 位于底部(我知道这违反了准则,但这就是设计)。 Fragment 之一也有标签,应该放在顶部,但它被标题栏遮住了。

如何将标签添加到Fragment,使其不被工具栏遮蔽?

这里是activity_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/bg_main"
    android:orientation="vertical">

    <android.support.v4.view.ViewPager
        android:id="@+id/fragments"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/bg_main_tabs"
        app:elevation="@dimen/elevation"
        app:tabIndicatorHeight="0dp"/>
</LinearLayout>

fragment_with_tabs.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/bg_main"
    android:orientation="vertical">

    <android.support.design.widget.TabLayout
        android:id="@+id/clothes_tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorAccent"
        app:tabIndicatorColor="@color/colorPrimaryDark"
        app:tabSelectedTextColor="@color/colorPrimaryDark"
        app:tabTextColor="@android:color/white" />

    <android.support.v4.view.ViewPager
        android:id="@+id/clothes_fragments"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>

【问题讨论】:

  • 删除app:elevation="@dimen/elevation"

标签: android android-fragments material-design android-tablayout


【解决方案1】:

将海拔设置为 0。从AppBarLayout 设置海拔是理想的,但无论如何你都可以这样做

getSupportActionBar().setElevation(0);

【讨论】:

  • 谢谢!但是,当其他片段可见时,如何返回高程?我必须在每个人中调用 setElevation 吗?
  • 是的。您需要为每个自定义提升行为设置高度。如果有帮助,请接受并投票。
猜你喜欢
  • 2018-07-21
  • 1970-01-01
  • 2016-11-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-10
  • 1970-01-01
相关资源
最近更新 更多