【问题标题】:How to remove shadow between default top Toolbar and TabBar | Android如何去除默认顶部工具栏和 TabBar 之间的阴影 |安卓
【发布时间】:2018-10-18 22:29:05
【问题描述】:

请任何人帮忙,我是 android 新手,我需要删除 Toolbar 和 TabBar 之间的阴影。我尝试了多种在线解决方案,但我的任何事情都不起作用.....请帮助我......

参考图片 enter image description here

活动 XML

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorIce"
    android:fadeScrollbars="true"
    android:isScrollContainer="true"
    tools:context=".HomeActivity">
    <android.support.v7.widget.Toolbar
        android:layout_height="wrap_content"
    android:layout_width="match_parent"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        style="@android:style/Widget.Material.ActionBar.TabBar"
        android:layout_width="match_parent"
        android:layout_height="50sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">
        <android.support.design.widget.TabItem
            android:id="@+id/tabItem"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="@string/tab_text_1" />
        <android.support.design.widget.TabItem
            android:id="@+id/tabItem2"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="@string/tab_text_2" />
    </android.support.design.widget.TabLayout>
    <android.support.v4.view.ViewPager
        android:id="@+id/container1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="-1dp"
        android:layout_marginEnd="-1dp"
        android:elevation="0sp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

【问题讨论】:

    标签: android android-studio material-design android-designer


    【解决方案1】:

    使用 AppBarLayout 包裹工具栏

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay"
        >
        <android.support.v7.widget.Toolbar
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
    </android.support.design.widget.AppBarLayout>
    

    在styles.xml中添加样式

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
        <item name="elevation">0dp</item>
    </style>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-21
      • 1970-01-01
      • 2020-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多