在为 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/