BaseActivity

Author Avatar
发达 7月 26, 2018
  • 在其它设备中阅读本文章
import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import com.gyf.barlibrary.ImmersionBar;

/**
 * @author : fada
 * Date : 2018/7/26
 * Description : input your description
 */
public abstract class BaseActivity<T extends ViewDataBinding> extends AppCompatActivity {
    public T mBinding;
    /**
     * 是否位于前台
     */
    protected ImmersionBar mImmersionBar;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        //状态栏
        mImmersionBar = ImmersionBar
                .with(this)
                .statusBarDarkFont(true, 0.2f);
        mImmersionBar.init();

        mBinding = DataBindingUtil.setContentView(this, getLayoutId());
    }

    /**
     * 获取布局id
     *
     * @return
     */
    protected abstract int getLayoutId();


    @Override
    protected void onDestroy() {
        mImmersionBar.destroy();
        super.onDestroy();
    }

    /**
     * 获取databinging
     * @return
     */
    public final T getBinding() {
        return mBinding;
    }
}