4.4 이상 BaseActivity 설정 상태막대 배경

4.4 및 일부 모델에서 상태막대 배경을 설정할 때 레이아웃 내용이 상태막대 위치에 삽입되는 문제를 해결하려면 전체 BaseActivity 코드가 다음과 같습니다.
    public class BaseActivity extends AppCompatActivity {

    public static CustomDialog mDialogWaiting;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (!App.activities.contains(this)){
            App.activities.add(this);
        }
        setStateBarColor(R.color.main);
    }


    @Override
    public void setContentView(@LayoutRes int layoutResID) {
        super.setContentView(layoutResID);
        ButterKnife.inject(this);
        excuteStatesBar();
    }

    @Override
    public void setContentView(View view) {
        super.setContentView(view);
        ButterKnife.inject(this);
        excuteStatesBar();
    }

    @Override
    public void setContentView(View view, ViewGroup.LayoutParams params) {
        super.setContentView(view, params);
        ButterKnife.inject(this);
        excuteStatesBar();
    }

    /**
     *   4.4         ,             
     */
    private void excuteStatesBar(){
        ViewGroup mContentView = (ViewGroup) getWindow().findViewById(Window.ID_ANDROID_CONTENT);
        View mChildView = mContentView.getChildAt(0);
        if (mChildView != null) {
            //       ContentView   FitsSystemWindows,
            //      ContentView       View ,      View    .
            mChildView.setFitsSystemWindows(true);
        }
    }

    /**
     *         
     * @param corlorId
     */
    public void setStateBarColor(int corlorId){
        StatusBarCompat.setStatusBarColor(this, getResources().getColor(corlorId));
    }


    /**
     *        
     */
    public Dialog showWaitingDialog(String tip) {
        hideWaitingDialog();
        View view = View.inflate(this, R.layout.dialog_waiting, null);
        if (!TextUtils.isEmpty(tip))
            ((TextView) view.findViewById(R.id.tvTip)).setText(tip);
        mDialogWaiting = new CustomDialog(this, view, R.style.dialog);
        mDialogWaiting.show();
        mDialogWaiting.setCancelable(true);
        return mDialogWaiting;
    }

    /**
     *      ,   setContentView()      
     */
    public void noStatesBar(){
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }

    /**
     *        
     */
    public static void hideWaitingDialog() {
        if (mDialogWaiting != null) {
            mDialogWaiting.dismiss();
            mDialogWaiting = null;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (App.activities.contains(this)){
            App.activities.remove(this);
        }
    }

}

좋은 웹페이지 즐겨찾기