fragment (3) 切换fragemnt时传递参数和加动画效果

切换fragemnt时传递参数

fragment A 中:

LoadUrlFragment loadUrlFragment = new LoadUrlFragment();
        Bundle b = new Bundle();
        b.putString("url_key",url);
        loadUrlFragment.setArguments(b);
        getSupportFragmentManager().beginTransaction().replace(R.id.container,loadUrlFragment).commit();

fragment B 中

@Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View root = inflater.inflate(R.layout.fragment_load_url,container,false);
        Bundle b = getArguments();
        String url = b.getString("url_key");
        WebView wv = (WebView) root.findViewById(R.id.webView);

        wv.loadUrl(url);

        return root;
    }


切换fragemnt时加动画效果  

fragment A 中:
loadUrlFragment.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left, R.anim.slide_in_left, R.anim.slide_out_right); 
 
   

你可能感兴趣的:(fragment)