2016-08-16 92 views
1

設置標高AppBarLayout時,我的ToolBar消失。這是佈局。爲AppBarLayout設置標高時,工具欄消失

<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

+0

檢查[this](http://stackoverflow.com/q/37778309/437146)發佈 – NightFury

+0

@NightFury謝謝。這解決了它。如果您可以發佈答案,我會將其設置爲已接受。 –

回答

2

新更新:在Appcompat v24.0.0中,無法使用setElevation()和app:elevation設置高程爲AppBarLayout,因爲它們已棄用。

您必須使用stateListAnimator屬性來立即設置高程。

注意:在StateListAnimator中將持續時間設置爲1ms以避免高程繪圖延遲。

AppBarLayout高程變化滯後於程序兼容性v24.0.0從@Zeeshan

+0

此方法已棄用。目標標高 現已棄用。 AppBarLayout的高程現在通過StateListAnimator進行控制。如果通過此方法或app:elevation attibute設置了目標高程,則會創建一個使用給定高程值的新狀態列表動畫器。 –

+1

這並不能解釋整個工具欄如何消失。即使方法和attr折舊,它也應該可以工作。 –

3

答案是完全正確的。

作爲額外這裏是一個示例代碼,工作

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不能正常工作,整個佈局正在消失。

相關問題