可以我们在代码中通过编程来改变状态栏或通知栏的位置吗?

huangapple go评论83阅读模式
英文:

can we change status bar or notification bar position programmatically

问题

我已将应用程序锁定为仅纵向模式,并且自行处理方向更改,但我意识到在横向模式下,状态栏保持不变,UI体验会很差。

现在,我已经按照要求开发了所有内容,唯一的解决方法似乎是通过编程方式更改状态栏位置,因为我不(实际上在这一点上不能)尊重系统方向更改。

这种可能吗?能够在我的应用程序内部以编程方式更改状态栏位置吗?一旦退出,恢复原样?

下面我已经说明了所需的效果:

首先,应用程序被锁定为纵向模式,当我旋转设备时,应用程序的视图会旋转,因为我解析原始传感器数据并应用旋转,但在这种情况下,状态栏不会旋转(因为应用程序被锁定为纵向模式,我只能访问应用程序的视图进行旋转):

可以我们在代码中通过编程来改变状态栏或通知栏的位置吗?

我如何实现上述内容的伪代码如下:

View views[] = new View[]{view1, view2, view3, view4 ....};
float rotationAngle = parseRawSensorData();//通常是加速度计输入
for(View view: views){
    rotateWithAngle(rotationAngle);
}

因此,视图会旋转,但状态栏会固定在原位。

我想要做的是能够使用以下代码旋转状态栏:

可以我们在代码中通过编程来改变状态栏或通知栏的位置吗?

即根据我获取的传感器数据旋转状态栏。

英文:

I had locked my app to portrait only mode and I handled orientation changes myself, but I realized that in landscape mode the status bar stays the same, and the UI experience would be bad.

Now, that I have developed everything accordingly, the only workaround seems to be for me is to change the status bar position programmatically, since I don't(or actually can't at this point) respect system orientation changes.

Is this possible? To change the status bar position programmatically? Only inside my app and restore once I exit?

Below I have illustrated the desired effect:

first, the app is locked to portrait mode and when I rotate the device the app's views rotate since I parse the raw sensor data and apply the rotation, but in this case the status bar doesn't rotate(since the app is locked to portrait mode, and I only have access to app's views for rotation):
可以我们在代码中通过编程来改变状态栏或通知栏的位置吗?

A pseudocode of how I've done the above is:

View views[] = new View[]{view1, view2, view3, view4 ....};
float rotationAngle = parseRawSensorData();//typically accelerometer input
for(View view: views){
    rotateWithAngle(rotationAngle);
}  

Therefore the views rotate but the status bar is affixed.

what I'd like to do is to be able to rotate the status bar using some code like this:
可以我们在代码中通过编程来改变状态栏或通知栏的位置吗?

i.e. rotate the statusbar according to the sensordata I fetch.

答案1

得分: 3

状态栏是Android系统的一部分,而不是您的应用程序的一部分。因此,您无法通过您的应用程序来控制它。

英文:

The statusbar is part of the Android system, not part of your application. So there is no way you could control that from your application.

答案2

得分: 0

不需要旋转状态栏,只需在使用应用程序时隐藏它。

导入:

import android.view.WindowManager

并且添加以下代码:

getWindow().setFlags(
        WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN
    );
英文:

Instead of rotating a status bar, you can just hide it when using your app.

Import:

import android.view.WindowManager

And write this:

getWindow().setFlags(
        WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN
    )

huangapple
  • 本文由 发表于 2020年9月20日 00:59:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/63971300.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定