2017-07-17 55 views
1

我試圖顯示全屏覆蓋視圖,第一步是設置帶有隱藏覆蓋層的xml,然後在適當時顯示它。這裏是我的佈局:使視圖重疊AppBarLayout

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_main" 
    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.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary"/> 
    </android.support.design.widget.AppBarLayout> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/appBar" 
     android:textColor="#FFFFFF" 
     android:text="Hello World!" /> 

    <View 
     android:id="@+id/overlay" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:clickable="true" 
     android:background="#80FF0000"/> 
</RelativeLayout> 

這裏是一個結果:

enter image description here

我需要得到這樣的:

enter image description here

所以,我成功地重疊的所有除AppBarLayout之外的屏幕。如何讓我的視圖被放置在AppBarLayout後面?

+0

嘿@WhiteNinja,是我的回答解決問題了嗎? – Karoly

+0

@ Karoly,nope ..我的問題是爲什麼用ID「overlay」查看不重疊AppBarLayout和如何解決它。 – WhiteNinja

回答

1

你應該在你的活動中使用此代碼:

public class MainActivity extends Activity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    // If the Android version is lower than Jellybean, use this call to hide 
    // the status bar. 
    if (Build.VERSION.SDK_INT < 16) { 
     getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
       WindowManager.LayoutParams.FLAG_FULLSCREEN); 
    } 
    setContentView(R.layout.activity_main); 
} 
... 

}

您可以按照谷歌官方教程: https://developer.android.com/training/system-ui/status.html

+0

這個答案不適合我的問題...而我的minSdk是19 – WhiteNinja