改变 ActionBar 高度
Changing ActionBar Height
我用这个
更改了themes.xml中的ActionBar高度
<item name="actionBarSize">30dp</item>
ActionBar 的高度发生变化,但随后它使我的第一个控件失去对齐。
在更改 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"
/>
我完全不知所措。
发生这种情况是因为操作栏在其样式中默认定义的最小高度为 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>
我用这个
更改了themes.xml中的ActionBar高度<item name="actionBarSize">30dp</item>
ActionBar 的高度发生变化,但随后它使我的第一个控件失去对齐。
在更改 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"
/>
我完全不知所措。
发生这种情况是因为操作栏在其样式中默认定义的最小高度为 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>