我处于全屏模式时无法在屏幕的底角绘制矩形表示没有可见的状态栏,也看不到导航栏
Display mdisp = getWindowManager().getDefaultDisplay();
Point mdispSize = new Point();
mdisp.getSize(mdispSize);
int maxX = mdispSize.x;
int maxY = mdispSize.y;
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawRect(0, maxY-pixel, pixel, MaxY);
}
这是在Kotlin,但它可以告诉你如何实现这一目标:
class MyView(context: Context, attributeSet: AttributeSet) : View(context, attributeSet) {
private var mHeight = 0
private var mWidth = 0
override fun onDraw(canvas: Canvas?) {
canvas?.drawRect(mWidth-100, mHeight-100, mWidth, mHeight)
}
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
super.onLayout(changed, left, top, right, bottom)
mHeight = bottom - top
mWidth = right - left
}
}