如何在非全屏横向模式下为切口/凹口区域着色

问题描述 投票:0回答:3

这是在横向模式下拍摄的两张图像。 一种是全屏模式,另一种是普通模式。 我试图解决的问题是如何为您在正常视图中看到的左侧白色区域着色。我希望颜色与应用程序的其余部分相同。无需担心全屏视图与纵向模式下的正常视图,效果很好。 关心的只是横向模式。

有人成功地在横向模式下为有凹口的设备的左侧着色吗?

An example of the the white area on the top and bottom of the left-hand notch. 左侧凹口顶部和底部的白色区域的示例。

No concern with full-screen mode. Working fine. 不用担心全屏模式。工作正常。

android landscape android-cutout
3个回答
6
投票

这是@AshrafAlshahawy 的修复:

  1. 创建目标颜色或图像的 BitmapDrawable。
  2. 在活动窗口上设置该可绘制对象。

示例:

    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 中进行了测试。


0
投票

这是@Java42 答案的修改版本。它使用

ColorDrawable
而不是
BitmapDrawable
,所以它有点短。

getWindow().setBackgroundDrawable(new ColorDrawable(Color.MAGENTA));

-1
投票

在您的主题中只需添加您想要的颜色:

<item name="android:statusBarColor" tools:targetApi="l">@color/black</item>
© www.soinside.com 2019 - 2024. All rights reserved.