简体   繁体   中英

Background image of screen size

I have a problem with the background image of my login activity. I can't remove the white bar at the top of the background image... Someone can help me?

In preview:

在此处输入图片说明

In my smartphone:

在此处输入图片说明

Here is my Relative Layout code:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/login_background"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.project.main.application.view.activity.Av_Login">

Add below line of code

requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
        if (Build.VERSION.SDK_INT < MINIMUM_API_LEVEL) {
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
        } else {
            getWindow().getDecorView().setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_FULLSCREEN);
        }

add Main Activity in onCreate before setContentView();

requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);

manifest activity add fullscreen theme

<activity android:name=".MainActivty"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen"/>

The status bar color matches to the colorPrimaryDark in your styles.xml (white in your case).

If you want to change this read this answer : How to change the status bar color in android

There is one more solution, but API level 19 is the limitation as well,
windowTranslucentStatus property.

style(v19)

<!-- Considering AppTheme as your app's theme -->
<style name="AppTheme.Trans" parent="AppTheme">
    <item name="android:windowTranslucentStatus">true</item>
</style>

Now apply that theme to your <activity> element in manifest

<activity
     android:name=".ui.login.SplashActivity"
     android:screenOrientation="portrait"
     android:theme="@style/AppTheme.Trans"
     android:windowSoftInputMode="adjustResize|stateHidden" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM