android - 为 AppBarLayout 设置高度时工具栏消失

标签 android android-support-library

在为 AppBarLayout 设置高度时,我的 ToolBar 消失了。这是布局。

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="@dimen/appbar_height"
    app:elevation="0dp"
    android:background="@color/transparent">

    <android.support.v7.widget.Toolbar
        style="@style/ToolBarStyle"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:elevation="0dp"
        android:background="@drawable/backgorund_toolbar_tranluscent"
        android:minHeight="@dimen/abc_action_bar_default_height_material" />
</android.support.design.widget.AppBarLayout>

我已经为 app:elevation 尝试了 0dp、0.1dp 和 4dp 等值。这里发生了什么事?它是支持库错误吗?我正在使用 24.0.0

最佳答案

@Zeeshan 的回答完全正确。

这里还有一个可以运行的示例代码

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            StateListAnimator stateListAnimator = new StateListAnimator();
            stateListAnimator.addState(new int[0], ObjectAnimator.ofFloat(appBarLayout, "elevation", 0.1f));
            appBarLayout.setStateListAnimator(stateListAnimator);
}

我不得不将高度设置为 0.1,因为将它设置为 0 不起作用,整个布局都在消失。

关于android - 为 AppBarLayout 设置高度时工具栏消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38969292/

相关文章:

android - 可以在非 UI 线程中运行 Robospice 监听器吗?

java - 查找用户输入的当前日期和时间之间的差异

android - 如何在 ActionMode 中禁用操作栏后退按钮

java - 在 android 中使用 android-support-v7-appcompat 库运行 PopupMenu 时出现 NoClassDefFoundError

android - 如何使用支持操作栏将默认主页显示为向上指示器?

android - 打开我的应用程序时如何显示用户的当前位置

android - 禁用 ListView 中的项目

android drawable选择器兼容性问题

android - 无法解析 com.android.support :support-compat:25. 4.0

android - fragment 标准过渡没有动画