首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >工具栏字幕被裁剪(它不适合高度)

工具栏字幕被裁剪(它不适合高度)
EN

Stack Overflow用户
提问于 2016-02-17 08:41:02
回答 6查看 2.6K关注 0票数 14

我的问题很简单,但我搞不懂:

当我试图显示一个字幕时,工具栏没有足够的空间来显示它并且被剪切。

工具栏:

代码语言:javascript
复制
<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 :

代码语言:javascript
复制
<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>
EN

回答 6

Stack Overflow用户

回答已采纳

发布于 2016-02-17 09:12:59

我使用了一个带有字幕的工具栏,在使用layout_height="wrap_content"的同时,我还添加了一个minHeight。这将确保您的工具栏至少是最低高度。我没有见过它在高度或作物上跳跃,但我总是有一个字幕集。

代码语言:javascript
复制
<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" />
票数 12
EN

Stack Overflow用户

发布于 2018-11-03 15:27:56

我使用layout_height=actionBarSize已经很长时间了,即使有字幕,也从来没有遇到过这个问题(在各种模拟器和像素电话上进行测试)。在看到我的字幕在三星Galaxy手机上被切断后,我现在使用了这个补丁。在我看来,这个问题取决于系统如何设置字幕间距。

我已经改用了新的材料部件(androidx)。因此,这个问题仍然存在于最新版本中。

使用wrap_content作为高度和actionBarSize属性作为minHeight的组合的解决方案不会在没有问题的情况下影响设备,因此在这些问题上,不会看到任何跳跃。

代码语言:javascript
复制
<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" />
票数 2
EN

Stack Overflow用户

发布于 2016-02-17 09:02:53

我建议您为工具栏创建一个新的布局,然后您可以填充它,但是您希望to.And在java代码中将它设置为ActionBar。因此,您将不再面临任何空间问题。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35451630

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档