2017-07-17 61 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