私は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()
}
}
}
これらは、レイアウト境界が表示されている場合と表示されていない場合の両方のスクリーンショットです。