在设计支持库中使用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