需要在布局文件中添加:android:fitsSystemWindows="true"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true">
调整颜色一致具体实现:
package com.justalk.cloud.sample.android.activity; import android.app.Activity; import android.content.Context; import android.graphics.Color; import android.os.Build; import android.os.Build.VERSION; import android.os.Build.VERSION_CODES; import android.os.Bundle; import android.view.MotionEvent; import android.view.View; import android.view.Window; import android.view.WindowManager; import android.view.inputmethod.InputMethodManager; import android.widget.EditText; import com.justalk.cloud.jusmcall.SystemBarTintManager; import com.justalk.cloud.sample.android.multicall.R; import com.justalk.cloud.sample.android.ui.XindunProgressDialog; public class BaseActivity extends Activity { private static final String TAG = "BaseActivity"; protected XindunProgressDialog mProgressDialog; private SystemBarTintManager tintManager; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { setTranslucentStatus(true); SystemBarTintManager tintManager = new SystemBarTintManager(this); tintManager.setStatusBarTintEnabled(true); tintManager.setStatusBarTintResource(R.color.titleColor);//通知栏所需颜色 } // if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) { // Window window = getWindow(); // window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, // WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); // // /* // * window.setFlags( // * WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, // * WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); // */ // // 创建状态栏的管理实例 // tintManager = new SystemBarTintManager(this); // // 激活状态栏设置 // tintManager.setStatusBarTintEnabled(true); // // 激活导航栏设置 // // tintManager.setNavigationBarTintEnabled(true); // // 设置一个颜色给系统栏 // // tintManager.setTintColor(Color.parseColor("#51c1cb")); // // tintManager.setNavigationBarTintColor(Color.BLACK); // } mProgressDialog = new XindunProgressDialog(this); mProgressDialog.setCanceledOnTouchOutside(false); } private void setTranslucentStatus(boolean on) { Window win = getWindow(); WindowManager.LayoutParams winParams = win.getAttributes(); final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; if (on) { winParams.flags |= bits; } else { winParams.flags &= ~bits; } win.setAttributes(winParams); } public void showProgress(String message) { if (mProgressDialog != null) { if (mProgressDialog.isShowing()) { mProgressDialog.dismiss(); } mProgressDialog.setMessage(message); mProgressDialog.show(); } } @Override protected void onResume() { // TODO Auto-generated method stub super.onResume(); } @Override public boolean dispatchTouchEvent(MotionEvent ev) { if (ev.getAction() == MotionEvent.ACTION_DOWN) { View v = getCurrentFocus(); if (isShouldHideInput(v, ev)) { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); if (imm != null) { imm.hideSoftInputFromWindow(v.getWindowToken(), 0); } } return super.dispatchTouchEvent(ev); } if (getWindow().superDispatchTouchEvent(ev)) { return true; } return onTouchEvent(ev); } public boolean isShouldHideInput(View v, MotionEvent event) { if (v != null && (v instanceof EditText)) { int[] leftTop = { 0, 0 }; v.getLocationInWindow(leftTop); int left = leftTop[0]; int top = leftTop[1]; int bottom = top + v.getHeight(); int right = left + v.getWidth(); if (event.getX() > left && event.getX() < right && event.getY() > top && event.getY() < bottom) { return false; } else { return true; } } return false; } }