Java 移除 android.widget.Toolbar 阴影
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43255496/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Remove android.widget.Toolbar shadow
提问by 0leg
Using API21+ Toolbar
:
使用 API21+ Toolbar
:
// Toolbar
Toolbar toolbar = new Toolbar(this);
toolbar.showOverflowMenu();
Would like to remove its shadow completely. setElevation(0)
doesn't do anything since getElevation()
already returns 0
.
想完全去除它的阴影。setElevation(0)
不做任何事情,因为getElevation()
已经返回0
。
There is Material Design reference:
有材料设计参考:
https://material.io/guidelines/layout/structure.html#structure-toolbars
https://material.io/guidelines/layout/structure.html#structure-toolbars
There is Develop Reference:
有开发参考:
https://developer.android.com/reference/android/widget/Toolbar.html
https://developer.android.com/reference/android/widget/Toolbar.html
But I don't see any info related to the shadow. Toolbar
但我没有看到任何与阴影相关的信息。 Toolbar
Question:how to remove/hide Toolbar
shadow completely?
问题:如何完全去除/隐藏Toolbar
阴影?
采纳答案by 0leg
I have found solution myself:
我自己找到了解决方案:
getActionBar().setElevation(0);
More info:
更多信息:
https://developer.android.com/reference/android/app/Activity.html#getActionBar()
https://developer.android.com/reference/android/app/Activity.html#getActionBar()
回答by ramin eftekhari
Use app:elevation="0dp"
instead of android:elevation
on your toolbar.
If it is not work, put your toolbar inside of a AppBarLayout
and set app:elevation="0dp"
:
在工具栏上使用app:elevation="0dp"
代替android:elevation
。如果它不起作用,请将您的工具栏放在 a 内AppBarLayout
并设置app:elevation="0dp"
:
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="0dp">
...
</android.support.design.widget.AppBarLayout>
回答by user1517638
Instead of android:elevation
try app:elevation
:
而不是android:elevation
尝试app:elevation
:
<android.support.design.widget.AppBarLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:elevation="0dp">
</android.support.design.widget.AppBarLayout>
回答by Ferdous Ahamed
Use attribute app:elevation="0dp"
to your Toolbar
or AppBarLayout
to remove the shadow.
使用属性app:elevation="0dp"
到您的Toolbar
或AppBarLayout
删除阴影。
#.If you are using Toolbar
only, then add attribute app:elevation="0dp"
to Toolbar
.
#. 如果您仅使用Toolbar
,则将属性添加app:elevation="0dp"
到Toolbar
.
<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"
app:elevation="0dp"/>
#.If you are using AppBarLayout
as a container of Toolbar
, then add attribute app:elevation="0dp"
to AppBarLayout
.
#. 如果您AppBarLayout
用作 的容器Toolbar
,则将属性添加app:elevation="0dp"
到AppBarLayout
.
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"
app:elevation="0dp">
<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>
OUTPUT:
输出:
UPDATE:
更新:
If you want to remove it programmatically then you can use below code:
如果要以编程方式删除它,则可以使用以下代码:
getSupportActionBar().setElevation(0);
Hope this will help~
希望这会有所帮助~
回答by Goodlife
回答by drakeet
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
appBarLayout.outlineProvider = null
}
回答by Mujeeb Rahaman T
If you are using AppBarLayout in toolbar, you can use:
app:elevation="0dp"
instead of
android:elevation
in AppBarLayout
如果您在工具栏中使用 AppBarLayout,则可以使用:
app:elevation="0dp"
代替
android:elevation
AppBarLayout
回答by Aslam Hossin
Put this code in Fragment
in which you want to hide the ToolBar
.
将此代码放入Fragment
要隐藏ToolBar
.
@Override
public void onResume() {
super.onResume();
((AppCompatActivity)getActivity()).getSupportActionBar().setElevation(0);
}
回答by Mingyong Gu
set "#00000000" to the backgroundColor of toolbar ,
remember that:
if you use CoordinatorLayout and AppBarLayout ,you should remove the
app:layout_behavior="@string/appbar_scrolling_view_behavior"
of your contentView , I have made this elementary mistake.
将“ #00000000”设置为工具栏的背景颜色,记住:如果你使用 CoordinatorLayout 和 AppBarLayout ,你应该删除
app:layout_behavior="@string/appbar_scrolling_view_behavior"
你的 contentView ,我犯了这个基本错误。