为什么我的应用程序无法覆盖整个屏幕?

时间:2018-09-01 04:41:43

标签: android android-layout

这里有2个屏幕截图

enter image description here

enter image description here

最重要的是我的应用。第二个是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>

布局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"?>

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
    android:allowBackup="true"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    android:icon="@drawable/ic_home_black_24dp">

    <activity
        android:name=".MainActivity"
        android:theme="@style/AppTheme"
        android:label="@string/app_name">

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

    </activity>
    <activity android:name=".EmailSignUp" />
    <activity android:name=".EmailVerification" />
    <activity android:name=".EmailSignIn" />
    <activity android:name=".Home" />
    <activity android:name=".AddLocation" />
    <activity android:name=".InstantMessage" />
    <activity android:name=".ProcessPayment" />

    <uses-library
        android:name="org.apache.http.legacy"
        android:required="false" />

    <meta-data
        android:name="preloaded_fonts"
        android:resource="@array/preloaded_fonts" />

    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

    <service android:name=".MyFirebaseMessagingService">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>

    <service android:name=".MyFirebaseInstanceIDService">
        <intent-filter>
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
        </intent-filter>
    </service>

</application>

4 个答案:

答案 0 :(得分:0)

使用这个主题

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

答案 1 :(得分:0)

您可以通过编程方式完成

您需要设置

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


                }
            }
        }
    }

对于Extra,还有其他更改系统用户界面的标志,例如全屏标志。

here,您可以找到所有标志。只需搜索system_ui_flag

答案 2 :(得分:0)

删除

android:layout_marginEnd="8dp"
                android:layout_marginStart="8dp"

            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"  

从linearEdit中删除这些行,其中linearLayout具有editText firstnName和lastName

或复制整个布局。我已将约束布局替换为相对布局

<?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"
xmlns:app="http://schemas.android.com/apk/res-auto">

<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/trans_orange" />

<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/white"
    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">

    <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_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="first_name"
                android:inputType="textPersonName"
                android:maxLength="30" />

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

        </LinearLayout>

        <RelativeLayout
            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"
                    android:layout_marginRight="8dp" />

                <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"
                    android:layout_marginRight="8dp" />

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

        </RelativeLayout>

        <RelativeLayout
            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:layout_marginLeft="8dp" />
        </RelativeLayout>

    </LinearLayout>
</ScrollView>

答案 3 :(得分:0)

我今天早上醒来,尝试再次运行它,一切看起来都很好。我绝对没有改变。 Android Studio /我的手机必须牢记自己的想法。