package com.base.browserwhite.label.fragment;

import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.fragment.app.Fragment;

import com.base.browserwhite.R;

import java.util.Random;

public class RedFragment extends Fragment {
    private View fragmentView;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        fragmentView = inflater.inflate(R.layout.fragment_red, container, false);
        int i = new Random().nextInt();
        if (i % 2 == 0) {
            fragmentView.setBackgroundColor(Color.RED);
        } else {
            fragmentView.setBackgroundColor(Color.BLUE);
        }
        return fragmentView;
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        // 缓存视图
        fragmentView = view;
    }

    public View getCachedView() {
        return fragmentView;
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        fragmentView = null;
    }
}