【问题标题】:how to set color in navigation bar in service如何在服务的导航栏中设置颜色
【发布时间】:2017-03-08 06:39:31
【问题描述】:

我想在导航栏中设置颜色,但它没有覆盖。即使我设置了 FLAG_LAYOUT_IN_SCREEN 。如何在服务中设置全屏透明布局。请帮帮我? **这是我的代码:**

View mView = new View(this);
mView.setBackgroundColor(shared.getColor());

    // get the WindowManager for the context-specific Display
    WindowManager wm = (WindowManager) getApplicationContext().getSystemService(WINDOW_SERVICE);

    // create the LayoutParams for the new Window
    WindowManager.LayoutParams params = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.MATCH_PARENT,//width
            WindowManager.LayoutParams.FILL_PARENT,//height
            WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,//xpos // TYPE_SYSTEM_ALERT is denied in apiLevel >=19
            WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,// flags
            PixelFormat.TRANSLUCENT //formats // the pixel format, here: translucent
    );
    wm.addView(mView, params);

【问题讨论】:

  • 一般来说,从服务中改变视图是个坏主意。很多用户认为你正在做的事情很烦人。如果你试图提醒用户,请尝试使用另一种方法。
  • 你能建议我吗,还有什么其他方法可以让颜色过滤像服务一样的视图?
  • 嗨@lisha,你找到解决方案了吗?
  • 不,你知道解决办法吗

标签: android android-layout android-studio layout navigation


【解决方案1】:

用下面的代码替换你的代码......

View mView = new View(this);
mView.setBackgroundColor(shared.getColor());

// get the WindowManager for the context-specific Display
WindowManager wm = (WindowManager) 
getApplicationContext().getSystemService(WINDOW_SERVICE);

// create the LayoutParams for the new Window
WindowManager.LayoutParams params = new WindowManager.LayoutParams();
int max = Math.max(getScreenWidth(), getScreenHeight());
params.type = TYPE_SYSTEM_OVERLAY;
    params.height = max + 200;
    params.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
            | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
            | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
    params.format = PixelFormat.TRANSPARENT;
wm.addView(mView, params);



//getting screen height and width
public static int getScreenWidth() {
    return Resources.getSystem().getDisplayMetrics().widthPixels;
}
public static int getScreenHeight() {
    return Resources.getSystem().getDisplayMetrics().heightPixels;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多