我用這個改變了 themes.xml 中的 ActionBar 高度
<item name="actionBarSize">30dp</item>
ActionBar 的高度發生了變化,但隨后它會導致我的第一個控制元件的對齊方式關閉。
在更改 ActionBar 高度之前:

更改操作欄高度后

第一個 Spinner 控制元件與 Layout 的頂部對齊
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".fragments.MainFragment">
<Spinner
android:id="@ id/spSessionsMain"
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="@drawable/background_spinner"
android:spinnerMode="dropdown"
app:layout_constraintLeft_toRightOf="parent"
app:layout_constraintRight_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
/>
我完全不知所措。
uj5u.com熱心網友回復:
發生這種情況是因為操作欄在其樣式中默認定義的最小高度為 64dp:
ActionBar 樣式:(僅供參考,請勿復制粘貼到您的主題中)
<style name="Widget.MaterialComponents.Light.ActionBar.Solid" parent="Widget.AppCompat.Light.ActionBar.Solid">
<item name="titleTextStyle">?attr/textAppearanceHeadline6</item>
<item name="subtitleTextStyle">?attr/textAppearanceSubtitle1</item>
<!-- Overrides minimum height in landscape to avoid headline6 and subtitle1 height concerns. -->
<item name="android:minHeight">@dimen/mtrl_toolbar_default_height</item>
<item name="maxButtonHeight">@dimen/mtrl_toolbar_default_height</item>
</style>
如果您想消除微調器和操作欄之間的間隙,您可以覆寫欄的最小高度。像這樣 :
<style name="CustomActionBar" parent="Widget.MaterialComponents.Light.ActionBar.Solid">
<item name="android:minHeight">30dp</item>
</style>
然后將此行添加到您的主題中:
<item name="actionBarStyle">@style/CustomActionBar</item>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/403853.html
標籤:
