admin
2022-01-28 760aee20870a34e6130a1c12237c5b747e2b00bd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.mugua.mgvideo.ui.common;
 
import android.os.Bundle;
import android.view.View;
 
import com.androidquery.AQuery;
import com.mugua.mgvideo.R;
import com.mugua.mgvideo.ui.BaseActivity;
 
import androidx.fragment.app.Fragment;
 
/**
 * @author hxh
 */
public class CommonFragmentActivity extends BaseActivity {
 
 
    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);
        setContentView(R.layout.activity_fragment);
        String title = getIntent().getStringExtra("title");
        String fragmentName = getIntent().getStringExtra("fragment");
 
        AQuery mAquery = new AQuery(this);
        mAquery.id(R.id.tv_title).text(title);
        mAquery.id(R.id.tv_back).clicked(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                CommonFragmentActivity.this.finish();
            }
        });
 
        Object fragment = null;
 
        try {
            Class clazz = Class.forName(fragmentName);
            fragment = clazz.newInstance();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        }
        if (fragment == null) {
            return;
        }
        getSupportFragmentManager().beginTransaction().replace(R.id.fl_container, (Fragment) fragment).commitAllowingStateLoss();
    }
}