Android 为什么我的应用程序没有填满整个屏幕?

Android 为什么我的应用程序没有填满整个屏幕?,android,android-layout,Android,Android Layout,这里我有两个截图 最重要的是我的应用程序。第二个是facebook。请注意,facebook占据了整个屏幕,而我的屏幕还没有达到顶部和底部。我如何让我的应用程序填满整个屏幕,或者至少让它扩展到时间和电池百分比之下 样式XML文件 <resources> <!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light"> <!-- Cu

这里我有两个截图

最重要的是我的应用程序。第二个是facebook。请注意,facebook占据了整个屏幕,而我的屏幕还没有达到顶部和底部。我如何让我的应用程序填满整个屏幕,或者至少让它扩展到时间和电池百分比之下

样式XML文件

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
    <!-- Customize your theme here. -->
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorBlack</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:textAllCaps">false</item>
    <item name="navigationViewStyle">@style/Widget.Design.NavigationView</item>
</style>

<style name="AppTheme.ActionBar">
    <item name="windowActionBar">true</item>
    <item name="windowNoTitle">false</item>
    <item name="android:textColorSecondary">@color/colorWhite</item>
    <item name="android:textColorPrimary">@color/colorWhite</item>
</style>

假的
真的
@颜色/原色
@彩色/彩色黑色
@颜色/颜色重音
假的
@style/Widget.Design.NavigationView
真的
假的
@彩色/彩色白色
@彩色/彩色白色

布局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:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
    android:id="@+id/btnApply"
    android:layout_width="0dp"
    android:layout_height="50dp"
    android:contentDescription="@null"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:srcCompat="@color/colorPrimary" />

<TextView
    android:id="@+id/txtApplyButton"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:contentDescription="@null"
    android:gravity="center_horizontal"
    android:text="APPLY"
    android:textColor="@color/colorWhite"
    app:fontFamily="@font/varela"
    app:layout_constraintBottom_toBottomOf="@+id/btnApply"
    app:layout_constraintEnd_toEndOf="@+id/btnApply"
    app:layout_constraintStart_toStartOf="@+id/btnApply"
    app:layout_constraintTop_toTopOf="@+id/btnApply" />

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:orientation="vertical"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <EditText
                android:id="@+id/txtFirstName"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="8dp"
                android:ems="10"
                android:hint="@string/first_name"
                android:inputType="textPersonName"
                android:maxLength="30"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <EditText
                android:id="@+id/txtLastName"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="8dp"
                android:ems="10"
                android:hint="@string/last_name"
                android:inputType="textPersonName"
                android:maxLength="30"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

        </LinearLayout>

        <android.support.constraint.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="8dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/linearLayout">

            <TextView
                android:id="@+id/txtLocation"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center_horizontal"
                android:text="Locations"
                android:textColor="@color/colorGray"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/txtLocation">

                <ImageView
                    android:id="@+id/btnAddLocation"
                    android:layout_width="30dp"
                    android:layout_height="30dp"
                    android:layout_marginEnd="8dp"
                    android:layout_weight="1"
                    android:contentDescription="@null"
                    app:srcCompat="@drawable/ic_add_black_24dp" />

                <ImageView
                    android:id="@+id/btnRemoveLocation"
                    android:layout_width="30dp"
                    android:layout_height="30dp"
                    android:layout_marginEnd="8dp"
                    android:layout_weight="1"
                    android:contentDescription="@null"
                    app:srcCompat="@drawable/ic_delete_black_24dp" />

                <Spinner
                    android:id="@+id/spnrLocations"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="50" />
            </LinearLayout>

        </android.support.constraint.ConstraintLayout>

        <android.support.constraint.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="8dp">

            <ImageView
                android:id="@+id/imgVerified"
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:contentDescription="@null"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <TextView
                android:id="@+id/txtVerified"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="8dp"
                android:fontFamily="@font/varela"
                android:textColor="@color/colorGreen"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintStart_toEndOf="@+id/imgVerified"
                app:layout_constraintTop_toTopOf="parent" />
        </android.support.constraint.ConstraintLayout>

    </LinearLayout>
</ScrollView>

显示

<?xml version="1.0" encoding="utf-8"?>


使用这一主题

<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:textAllCaps">false</item>
</style>

假的
真的
@颜色/原色
@颜色/原色暗
@颜色/颜色重音
假的

您可以通过编程方式执行此操作

你需要准备一下

getWindow().getDecorView().setSystemUiVisibility(flag);
在活动的onWindowFocusChanged(onWindowFocusChanged)中设置这些标志 主要用于全屏显示,因此即使在焦点更改后,您也可以保留全屏显示。您还可以在onCreate中或您喜欢的位置设置标志)

在你的活动中,你可以像

@Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if (hasFocus) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

   //You can also pass multiple flags as i did. one for hide navigation one for make layout stable
   getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                                       |View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);


                }
            }
        }
    }
另外,还有其他改变系统ui的标志,比如全屏显示的标志


你可以找到所有的旗帜。只需搜索system\u ui\u flag

我今天早上醒来,再次尝试运行它,一切看起来都很好。我什么也没变。Android studio/我的手机必须有自己的想法。

你能添加与第一个相关的代码吗screenshot@Garren,您可以发送activity的java、layout.xml和AnroidManifest吗?你想让黑色状态栏更苗条吗?我可以启动一个新项目并在手机上运行它,它看起来很好,所以我必须更改布局文件中的某些内容,只是不知道它是什么。我编辑了我的帖子以显示布局xml文件。你能显示你的清单吗?@AshwiniViolet我添加了清单。我尝试过用“新建项目向导”中的默认文件替换所有项目文件,但它仍然显示不正确,但当我运行“新建项目向导”时,它创建的文件与我在项目中创建的文件完全相同,它运行得很好。所以问题出在其他地方。它仍然拒绝垂直显示编辑的整个屏幕。该问题发生在应用程序的所有活动中。无论哪种布局可见,大小都是一致的。
@Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if (hasFocus) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

   //You can also pass multiple flags as i did. one for hide navigation one for make layout stable
   getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                                       |View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);


                }
            }
        }
    }