0% found this document useful (0 votes)
3 views

Practical 5 Java

This Java code defines a MainActivity class for an Android application that enables edge-to-edge display. It sets up the activity's layout and adjusts padding based on system bar insets to ensure content is displayed correctly. The code utilizes the ViewCompat class to handle window insets dynamically.

Uploaded by

jagadalesanika24
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Practical 5 Java

This Java code defines a MainActivity class for an Android application that enables edge-to-edge display. It sets up the activity's layout and adjusts padding based on system bar insets to ensure content is displayed correctly. The code utilizes the ViewCompat class to handle window insets dynamically.

Uploaded by

jagadalesanika24
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

package com.example.

myapplication;

import android.os.Bundle;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v,
insets) -> {
Insets systemBars =
insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right,
systemBars.bottom);
return insets;
});
}
}

You might also like