You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
package net.micode.notes ;
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 ) ;
// 设置Activity的布局为activity_main.xml
setContentView ( R . layout . activity_main ) ;
// 为ID为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 ;
} ) ;
}
}