在設計支持庫中使用AppBarLayout
小部件時,工具欄底部會出現陰影。我怎樣才能消除這個影子?在AppBarLayout小部件下面移除陰影Android
回答
只需使用app:elevation="0dp"
刪除陰影。它一直爲我工作。希望對你有效。
我試過app:elevation="0dp"
,但工具欄消失,但使用app:elevation="0.1dp"
發揮了訣竅。
希望這可以幫助別人。
0.1dp也不起作用,它也隱藏了工具欄菜單。 –
我有一個appcompat v23.0.1使用這個技巧的工作應用程序,你有什麼版本? –
我使用'v25.0.0'。 –
出現此問題時API版本> = 21,如果你不想修改標高,你可以使用:
appBar.setOutlineProvider(null);
記得檢查API版本
編輯:
Blow是setOutlineProvider
的源代碼。
/**
* Sets the {@link ViewOutlineProvider} of the view, which generates the Outline that defines
* the shape of the shadow it casts, and enables outline clipping.
* <p>
* The default ViewOutlineProvider, {@link ViewOutlineProvider#BACKGROUND}, queries the Outline
* from the View's background drawable, via {@link Drawable#getOutline(Outline)}. Changing the
* outline provider with this method allows this behavior to be overridden.
* <p>
* If the ViewOutlineProvider is null, if querying it for an outline returns false,
* or if the produced Outline is {@link Outline#isEmpty()}, shadows will not be cast.
* <p>
* Only outlines that return true from {@link Outline#canClip()} may be used for clipping.
*
* @see #setClipToOutline(boolean)
* @see #getClipToOutline()
* @see #getOutlineProvider()
*/
public void setOutlineProvider(ViewOutlineProvider provider) {
mOutlineProvider = provider;
invalidateOutline();
}
據說If the ViewOutlineProvider is null, if querying it for an outline returns false, or if the produced Outline is {@link Outline#isEmpty()}, shadows will not be cast.
所以,如果你想刪除的影子,你最好使用此方法,而不是設置app:elevation
。看起來像改變高程去除陰影是一種副作用。在某些情況下更改高程可能會導致其他問題。
這是我想出app:elevation="0dp"
去除陰影的方式。完美的作品。
使用最新的appcompat版本,xml中的技巧設置app:elevation="0.1dp"
不再適用。
到目前爲止,我找到了兩種解決方案。
而不是設置
app:elevation
,儘量使用stateListAnimator。例如,在代碼: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); }
一個更簡單的方法是你是否還在爲XML正常設置
app:elevation="0dp"
,但代碼:appBarLayout.bringToFront();
幸得這兩個討論:
ToolBar disappears when setting elevation for AppBarLayout
when set app:elevation="0dp" then hamburgermenu not showing to toolbar
第二個解決方案適用於我和似乎很容易 –
在您的AppBarLayout上添加應用:elevation =「0dp」。像這樣的例子
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="0dp"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
編程您可以使用此: getSupportActionBar()setElevation(0。0F);
- 1. 刪除AppBarLayout下面陰影
- 2. Android:圖庫小部件和陰影
- 3. 如何在NavigationView下移除陰影?
- 4. 在沒有Sherlock的情況下移除ActionBar下面的陰影
- 5. 在KineticJS中移除陰影
- 6. 從底部移除盒子的陰影
- 7. 無法在AppBarLayout/CollapsingToolbar上獲得陰影
- 8. 散焦調整大小 - 陰謀部分陰影小部件
- 9. 雙面箱子陰影在雙面箱子陰影頂部
- 10. AppBarLayout和工具欄設置無陰影
- 11. 如何在Qt中的小部件下繪製陰影?
- 12. 刪除navigationDrawer頂部「陰影」
- 13. 刪除下拉陰影
- 14. 底部陰影到ListPopupWindow android
- 15. Android的陰影下邊框
- 16. 頁面捲曲陰影也在頂部?
- 17. 從UIWebView刪除頂部/底部陰影?
- 18. 在Android中刪除陰影PopupWindow
- 19. 去除python表面陰影中的陰影
- 20. 從彈出窗口移除陰影
- 21. 從jQuery fancybox中移除陰影1.3.4
- 22. 從提取前景中移除陰影
- 23. 在Three.JS中移動陰影
- 24. R陰影的陰影部分
- 25. Android小部件AppBarLayout總是排在最前
- 26. Android內陰影
- 27. 如何設置一個盒子陰影的div元素的所有方面,左陰影,右陰影,頂部陰影,底部陰影?
- 28. Android DrawerLayout,CoordinatorLayout和AppBarLayout下的AppBarLayout空白
- 29. WPF陰影大小
- 30. 如何去除UINavigationBar的底部陰影?
謝謝:)爲我工作.. –
我用android:提升< - 這不工作。 –
請勿使用android:高程。使用應用程序:海拔。 – radley