我的问题很简单,但我搞不懂:
当我试图显示一个字幕时,工具栏没有足够的空间来显示它并且被剪切。
工具栏:
<android.support.v7.widget.Toolbar 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="?android:actionBarSize"
android:layout_centerHorizontal="true"
app:theme="@style/MyToolBar">
?android:actionBarSize的高度不足以正确显示标题和字幕吗?
当我将ToolBar高度设置为wrap_content时,一切正常,但有人能向我解释我应该如何正确地设置高度吗?
styles.xml :
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowBackground">@color/background1</item>
<item name="android:textColorPrimary">@color/colorAccent</item>
<!-- Customize your theme here. -->
</style>
<style name="MyToolBar" parent="Widget.AppCompat.ActionBar">
<!-- Support library compatibility -->
<item name="android:textColorPrimary">@color/colorAccent</item>
<item name="android:textColorSecondary">@color/colorAccent</item>
<item name="colorControlNormal">@color/colorAccent</item>
</style>发布于 2016-02-17 09:12:59
我使用了一个带有字幕的工具栏,在使用layout_height="wrap_content"的同时,我还添加了一个minHeight。这将确保您的工具栏至少是最低高度。我没有见过它在高度或作物上跳跃,但我总是有一个字幕集。
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="@dimen/default_elevation"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />发布于 2018-11-03 15:27:56
我使用layout_height=actionBarSize已经很长时间了,即使有字幕,也从来没有遇到过这个问题(在各种模拟器和像素电话上进行测试)。在看到我的字幕在三星Galaxy手机上被切断后,我现在使用了这个补丁。在我看来,这个问题取决于系统如何设置字幕间距。
我已经改用了新的材料部件(androidx)。因此,这个问题仍然存在于最新版本中。
使用wrap_content作为高度和actionBarSize属性作为minHeight的组合的解决方案不会在没有问题的情况下影响设备,因此在这些问题上,不会看到任何跳跃。
<androidx.appcompat.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:actionBarSize" />发布于 2016-02-17 09:02:53
我建议您为工具栏创建一个新的布局,然后您可以填充它,但是您希望to.And在java代码中将它设置为ActionBar。因此,您将不再面临任何空间问题。
https://stackoverflow.com/questions/35451630
复制相似问题