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.

54 lines
1.6KB

  1. package com.example.tidalairpeisong.view;
  2. import android.annotation.TargetApi;
  3. import android.content.Context;
  4. import android.os.Build;
  5. import android.util.AttributeSet;
  6. import android.view.View;
  7. import android.view.WindowInsets;
  8. import android.widget.FrameLayout;
  9. /**
  10. * @ProjectName: NewProject
  11. * @Package: com.example.tidalair.view
  12. * @ClassName: WindowInsetsFrameLayout
  13. * @Description: java类作用描述
  14. * @Author: csd
  15. * @CreateDate: 2021/10/19 23:15
  16. * @UpdateRemark: 更新说明
  17. * @Version: 1.0
  18. */
  19. public class WindowInsetsFrameLayout extends FrameLayout {
  20. public WindowInsetsFrameLayout(Context context) {
  21. this(context, null);
  22. }
  23. public WindowInsetsFrameLayout(Context context, AttributeSet attrs) {
  24. this(context, attrs, 0);
  25. }
  26. @TargetApi(Build.VERSION_CODES.LOLLIPOP)
  27. public WindowInsetsFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) {
  28. super(context, attrs, defStyleAttr);
  29. setOnHierarchyChangeListener(new OnHierarchyChangeListener() {
  30. @Override
  31. public void onChildViewAdded(View parent, View child) {
  32. requestApplyInsets();
  33. }
  34. @Override
  35. public void onChildViewRemoved(View parent, View child) {
  36. }
  37. });
  38. }
  39. @TargetApi(Build.VERSION_CODES.KITKAT_WATCH)
  40. @Override
  41. public WindowInsets onApplyWindowInsets(WindowInsets insets) {
  42. int childCount = getChildCount();
  43. for (int index = 0; index < childCount; index++)
  44. getChildAt(index).dispatchApplyWindowInsets(insets);
  45. return insets;
  46. }
  47. }