首页 > 解决方案 > 巨大的下巴出现在应用程序窗口的顶部

问题描述

我正在编辑Sipdroid并对 UI 进行更改,但此应用程序中的每个活动都有一个巨大的下巴,我似乎无法以任何方式隐藏。看起来它被识别为状态栏,正如您从我在下面共享的代码中看到的那样,而且每当我更改状态栏颜色时,下巴也会变成该颜色。到目前为止,我发现它不在屏幕顶部创建填充的唯一方法是添加<item name="android:windowTranslucentStatus">true</item>到样式 XML。
以下是布局 XML 文件和 Kotlin 类的代码:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/hello"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="Hello World"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
package org.sipdroid.sipua.ui

import android.app.Activity
import android.graphics.Rect
import android.os.Bundle
import android.view.View
import android.view.Window
import android.widget.TextView
import android.widget.Toast
import org.sipdroid.sipua.R

class TestActivity : Activity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_test)

        val btn = findViewById<TextView>(R.id.hello)
        btn.setOnClickListener {
            // gets the status bar height
            val rectangle = Rect()
            window.decorView.getWindowVisibleDisplayFrame(rectangle)
            val statusBarHeight = rectangle.top
            val contentViewTop = window.findViewById<View>(Window.ID_ANDROID_CONTENT).top
            val titleBarHeight = contentViewTop - statusBarHeight

            // makes the TextView as high as the status bar,
            // so we have a visual representation of the
            // actual height with layout bounds visible
            btn.height = statusBarHeight

            Toast.makeText(
                this@TestActivity,
                "$statusBarHeight $titleBarHeight ${rectangle.height()}",
                Toast.LENGTH_SHORT
            ).show()
        }
    }
}

这些是显示和不显示布局边界的屏幕截图。

标签: androidstatusbarsipdroid

解决方案


在 setContentView() 之前添加getActionBar().hide()onCreate 方法


推荐阅读