Button/Content in Linear layout showing in Status bar/ Top bar (android studio)


I just change main layout in "Linear Layout" then button showing behind the App bar and inside the TOP bar/ status bar. How to fix this.

enter image description here

code is here

<?xml version="1.0" encoding="utf-8"?>
<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:id="@+id/xmlActivityMain"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <Button
        android:id="@+id/btnOpenAdminAct"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20dp"
        android:text="openAdminAct" />

    <Button
        android:id="@+id/btn_token"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="token copy"
        />
    <TextView
        android:id="@+id/textView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="212dp"
        android:text="show token or error here"
        android:textSize="20sp"
        />

</LinearLayout>
0
Sep 4 at 10:10 AM
User AvatarTexD
#android#xml#android-studio#android-layout

Accepted Answer

<?xml version="1.0" encoding="utf-8"?>
<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:id="@+id/xmlActivityMain"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:fitsSystemWindows="true" 
    tools:context=".MainActivity">
    
    <!-- Buttons and TextViews go here -->
    
</LinearLayout>

Add the android:fitsSystemWindows="true" attribute to the root LinearLayout in the XML file. This tells the Android system to automatically add padding to ensure the layout content doesn't overlap with the system bars.

User AvatarInfant developer
Sep 4 at 11:31 AM
3