我试图显示全屏覆盖视图,第一步是使用隐藏的覆盖设置xml,然后在适当时显示它。这是我的布局:

<?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>


结果如下:

android - 使 View 与AppBarLayout重叠-LMLPHP

我需要这样的结果:

android - 使 View 与AppBarLayout重叠-LMLPHP

因此,我成功地重叠了除AppBarLayout之外的所有屏幕。如何使我的视图放置在AppBarLayout之上而不是其后?

最佳答案

您应该在活动中使用以下代码:

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);
}
...


}

您可以按照以下官方Google教程进行操作:
https://developer.android.com/training/system-ui/status.html

关于android - 使 View 与AppBarLayout重叠,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45148054/

10-10 09:46