package cn.zhaoliang5156.toutiao1630a.base;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.WindowManager;
/**
* Activity 基类
*
* @author zhaoliang
* @version 1.0
* @create 2018/7/24
*/
public abstract class BaseActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
init();
}
/**
* 初始化
*/
private void init() {
setFullScreen();
setContentView(initLayout());
findView();
setOnClickLisener();
initData();
}
/**
* 设置点击事件
*/
protected abstract void setOnClickLisener();
/**
* 初始化数据
*/
protected abstract void initData();
/**
* 查找控件
*/
protected abstract void findView();
/**
* 设置全屏
*/
protected abstract void setFullScreen();
/**
* 填充布局
*
* @return
*/
protected abstract int initLayout();
/**
* 全屏
*/
protected void fullScreen() {
// 设置全屏
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}
/基类Fragment
package cn.zhaoliang5156.toutiao1630a.base;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
/**
* 基类Fragment
*/
public abstract class BaseFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return initLayout(inflater, container);
}
/**
* 填充布局
*
* @param inflater
* @param container
* @return
*/
protected abstract View initLayout(LayoutInflater inflater, ViewGroup container);
}