设置状态栏和应用颜色统一时,重叠

需要在布局文件中添加: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;
   }
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值