1

我一直有一個相當難的問題,弄清楚如何擺脫操作欄頂部的黑線。鏈接中有一張圖片顯示黑線的位置。我想知道是否有辦法擺脫它。這看起來像是一個非常簡單的問題,但我無法在網上找到關於如何擺脫它的任何內容。刪除操作欄頂部的深色

任何幫助表示讚賞

這裏是我的XML佈局

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" android:layout_height="match_parent"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/appbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingTop="@dimen/appbar_padding_top" 
     android:theme="@style/AppTheme.AppBarOverlay" 
     android:layout_alignParentTop="true" 
     style="@style/Base.Theme.AppCompat.Light"> 

     <android.support.design.widget.TabLayout 
      android:id="@+id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:fillViewport="false" /> 

    </android.support.design.widget.AppBarLayout> 

</RelativeLayout> 

回答

1

確保包含AppBarLayout活動有包括這些屬性的主題:

<item name="windowActionBar">false</item> 
    <item name="windowNoTitle">true</item> 

使用的AppBarLayout有效地創建自己的應用程序欄(以前稱爲Action Bar),而不是使用內置系統。但是,如果你的主題沒有隱藏系統應用欄,你最終會得到兩個,這可能會導致你看到的神器。

此外,我不相信你需要在你的AppBarLayout中的android:paddingTopapp:elevationstyle屬性。下面是從我AppBarLayout代碼在我的活動頂部的標籤,它完美的作品對我來說:

<android.support.design.widget.AppBarLayout 
     android:id="@+id/appbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.design.widget.TabLayout 
      android:id="@+id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      app:tabIndicatorColor="@android:color/white"/> 

    </android.support.design.widget.AppBarLayout> 

不過,你可能想在有一個工具欄爲你的動作條的使用,就像這樣:

<android.support.design.widget.AppBarLayout 
     android:id="@+id/appbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:layout_scrollFlags="scroll|enterAlways" 
      app:popupTheme="@style/AppTheme.PopupOverlay"> 

     </android.support.v7.widget.Toolbar> 

     <android.support.design.widget.TabLayout 
      android:id="@+id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      app:tabIndicatorColor="@android:color/white"/> 

    </android.support.design.widget.AppBarLayout> 
在活動的 onCreate()方法

然後,請確保您設置了工具欄的動作條像這樣:

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
    setSupportActionBar(toolbar); 
+0

我得到一個錯誤java.lang.IllegalStateException:這個Activity已經有一個窗口裝飾提供的操作欄。請勿在您的主題中請求Window.FEATURE_SUPPORT_ACTION_BAR並將windowActionBar設置爲false以使用工具欄。我檢查了我設置windowActionBar爲false,所以我不知道是什麼造成它 – thequantumgamer01

+0

請確保你沒有設置'android:windowActionBar'。它不同於'windowActionBar'(沒有'android:'前綴 - 它在兼容庫中,而不是Android系統)。 – drmercer

+0

如果這不起作用,請將該活動的主題擴展爲'Theme.AppCompat.NoActionBar'或'Theme.AppCompat.Light.NoActionBar'。 – drmercer

2

添加到您的AppBar佈局:

app:elevation="0dp" 

您的固定XML佈局:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" android:layout_height="match_parent"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/appbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingTop="@dimen/appbar_padding_top" 
     android:theme="@style/AppTheme.AppBarOverlay" 
     android:layout_alignParentTop="true" 
     app:elevation="0dp" 
     style="@style/Base.Theme.AppCompat.Light"> 

     <android.support.design.widget.TabLayout 
      android:id="@+id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:fillViewport="false" /> 

    </android.support.design.widget.AppBarLayout> 

</RelativeLayout> 

而且,試試這個:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/main_content" 
    android:layout_width="match_parent" android:layout_height="match_parent" 
    android:fitsSystemWindows="true"> 

    <android.support.design.widget.AppBarLayout android:id="@+id/appbar" 
     android:layout_width="match_parent" android:layout_height="wrap_content" 
     android:paddingTop="@dimen/appbar_padding_top" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <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/AppTheme.PopupOverlay" 
      app:layout_scrollFlags="scroll|enterAlways"> 

     </android.support.v7.widget.Toolbar> 

     <android.support.design.widget.TabLayout android:id="@+id/tabs" 
      android:layout_width="match_parent" android:layout_height="wrap_content" /> 

    </android.support.design.widget.AppBarLayout> 

</android.support.design.widget.CoordinatorLayout> 
+0

我嘗試過,但在頂部的暗線仍然出現 – thequantumgamer01

+0

查看更新版本! –

+0

沒有,仍然不起作用 – thequantumgamer01