这是在横向模式下拍摄的两张图像。 一种是全屏模式,另一种是普通模式。 我试图解决的问题是如何为您在正常视图中看到的左侧白色区域着色。我希望颜色与应用程序的其余部分相同。无需担心全屏视图与纵向模式下的正常视图,效果很好。 关心的只是横向模式。
有人成功地在横向模式下为有凹口的设备的左侧着色吗?
这是@AshrafAlshahawy 的修复:
示例:
Bitmap bitmap = Bitmap.createBitmap(24, 24, Bitmap.Config.ARGB_8888);
bitmap.eraseColor(Color.MAGENTA);
BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), bitmap);
getWindow().setBackgroundDrawable(bitmapDrawable);
另一个例子:
Bitmap bitmap = Bitmap.createBitmap(24, 24, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.drawColor(Color.MAGENTA);
BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), bitmap);
getWindow().setBackgroundDrawable(bitmapDrawable);
都在 Activity.onCreate 中进行了测试。
这是@Java42 答案的修改版本。它使用
ColorDrawable
而不是 BitmapDrawable
,所以它有点短。
getWindow().setBackgroundDrawable(new ColorDrawable(Color.MAGENTA));
在您的主题中只需添加您想要的颜色:
<item name="android:statusBarColor" tools:targetApi="l">@color/black</item>