简体   繁体   中英

Extend color background in Android Studio

I started to work with Android Studio, i created a small app and set background:

android:background="#3F51B5"

but when i run the emulator i see a lower white/dark band, specially in smartphone with larger displays

what can i do?

i use linear layout and one section with constraintlayout. the first portion of main activity is

<LinearLayout 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="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="false"
android:background="#3F51B5"
android:orientation="vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp"
tools:context=".MainActivity"
tools:visibility="visible">

do like this:

android:layout_width="match_parent"
android:layout_height="match_parent"

with this way you can fill all the display with the color that you choose

If you wish to keep your LinearLayout as is but the full background as the colour you want, then I suggest wrapping this in a ConstraintLayout whose width and length can be match parent, or height can be wrap content as per your need

<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto"
    
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#3F51B5">

    <LinearLayout 
           xmlns:tools="http://schemas.android.com/tools"       
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_alignParentStart="false"
           
           android:orientation="vertical"
           android:paddingLeft="16dp"
           android:paddingRight="16dp"
           tools:context=".MainActivity"
           tools:visibility="visible"> 
           //Views 
     </LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>



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