ToolBar disappears when adjusting height for AppBarLayout

My ToolBar disappears when setting the height for AppBarLayout . Here is the layout.

 <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> 

I tried values ​​like 0dp, 0.1dp and 4dp for app:elevation . What's going on here? Is this a support library bug? I am using 24.0.0 .

+1
android android-support-library
Aug 16 '16 at 7:47
source share
2 answers

New update: in Appcompat v24.0.0 you cannot set the elevation in AppBarLayout using setElevation () and app: elevation as they are deprecated.

You should use the stateListAnimator property to set the height now.

Note: set the duration to 1 ms in StateListAnimator to avoid delay in drawing.

AppBarLayout application height change delayed by appCompat v24.0.0

+2
Aug 16 '16 at 7:52
source share

The answer from @Zeeshan is absolutely right.

as additional here is an example of code that works

 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); } 

I needed to set the height to 0.1, because setting it to 0 did not work, the whole layout disappeared.

+3
Feb 16 '17 at 18:31
source share



All Articles