content: package com.example.vibemusicplayer.ui.fragment;
  
  import android.annotation.SuppressLint;
  import android.os.Bundle;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.CompoundButton;
  import android.widget.Switch;
  
  import androidx.annotation.NonNull;
  import androidx.annotation.Nullable;
  import androidx.appcompat.app.AppCompatDelegate;
  import androidx.fragment.app.Fragment;
  
  import com.example.vibemusicplayer.R;
  
  public class SettingsFragment extends Fragment {
  
      public static SettingsFragment newInstance() {
          return new SettingsFragment();
      }
  
      @Override
      public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
                               @Nullable Bundle savedInstanceState) {
          return inflater.inflate(R.layout.fragment_settings, container, false);
      }
  
      @Override
      public void onActivityCreated(@Nullable Bundle savedInstanceState) {
          super.onActivityCreated(savedInstanceState);
  
          @SuppressLint("UseSwitchCompatOrMaterialCode") Switch switchDarkMode = requireActivity().findViewById(R.id.item_dark_switch);
          switchDarkMode.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
              @Override
              public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                  if (isChecked) {
                      // 切换到深色模式
                      AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
                  } else {
                      // 切换到浅色模式
                      AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
                  }
              }
          });
      }
  
  }