Android 删除操作栏下方的阴影
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12246388/
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 shadow below actionbar
提问by Micha? K
I use actionbarsherlock. The piece of code below is responsible for changing it's background to a custom one.
我使用 actionbarsherlock。下面的一段代码负责将其背景更改为自定义背景。
<style name="Widget.Styled.ActionBar" parent="Widget.Sherlock.ActionBar">
<item name="background">@drawable/actionbar_bg</item>
<item name="android:background">@drawable/actionbar_bg</item>
<...>
</style>
<style name="Theme.MyApp" parent="@style/Theme.Sherlock.Light">
<item name="actionBarStyle">@style/Widget.Styled.ActionBar</item>
<item name="android:actionBarStyle">@style/Widget.Styled.ActionBar</item>
<..>
</style>
And it works for actionbarsherlock (on versions below honeycomb). But in ICS I have a shadow below actionbar which I don't want. What is the style item to make it disappear?
它适用于 actionbarsherlock(在蜂窝以下的版本上)。但是在 ICS 中,我不想要的操作栏下方有一个阴影。让它消失的样式项是什么?
回答by Tomer Mor
What is the style item to make it disappear?
让它消失的样式项是什么?
In order to remove the shadow add this to your app theme:
为了去除阴影,将其添加到您的应用主题中:
<style name="MyAppTheme" parent="android:Theme.Holo.Light">
<item name="android:windowContentOverlay">@null</item>
</style>
UPDATE:As @Quinny898 stated, on Android 5.0 this has changed, you have to call setElevation(0)
on your action bar. Note that if you're using the support library you must call it to that like so:
更新:正如@Quinny898 所说,在 Android 5.0 上这已经改变了,你必须调用setElevation(0)
你的操作栏。请注意,如果您正在使用支持库,则必须像这样调用它:
getSupportActionBar().setElevation(0);
回答by Sloosh
For Android 5.0, if you want to set it directly into a style use:
对于Android 5.0,如果你想直接设置成样式使用:
<item name="android:elevation">0dp</item>
and for Support library compatibility use:
和支持库兼容性使用:
<item name="elevation">0dp</item>
Example of style for a AppCompat light theme:
AppCompat 灯光主题的样式示例:
<style name="Theme.MyApp.ActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<!-- remove shadow below action bar -->
<!-- <item name="android:elevation">0dp</item> -->
<!-- Support library compatibility -->
<item name="elevation">0dp</item>
</style>
Then apply this custom ActionBar style to you app theme:
然后将此自定义 ActionBar 样式应用于您的应用程序主题:
<style name="Theme.MyApp" parent="Theme.AppCompat.Light">
<item name="actionBarStyle">@style/Theme.MyApp.ActionBar</item>
</style>
For pre 5.0 Android, add this too to your app theme:
对于 5.0 之前的 Android,也将其添加到您的应用主题中:
<!-- Remove shadow below action bar Android < 5.0 -->
<item name="android:windowContentOverlay">@null</item>
回答by Kieron
On Android 5.0 this has changed, you have to call setElevation(0) on your action bar. Note that if you're using the support library you must call it to that like so:
在 Android 5.0 上,这已更改,您必须在操作栏上调用 setElevation(0)。请注意,如果您正在使用支持库,则必须像这样调用它:
getSupportActionBar().setElevation(0);
It's unaffected by the windowContentOverlay style item, so no changes to styles are required
它不受 windowContentOverlay 样式项的影响,因此不需要更改样式
回答by Vijay Vavdiya
add app:elevation="0dp"
in AppBarLayout for hiding shadow in appbar
添加app:elevation="0dp"
AppBarLayout 以隐藏应用栏中的阴影
回答by Dmitry Zaytsev
If you are working with ActionBarSherlock
如果您正在使用 ActionBarSherlock
In your theme add this:
在您的主题中添加:
<style name="MyTheme" parent="Theme.Sherlock">
....
<item name="windowContentOverlay">@null</item>
<item name="android:windowContentOverlay">@null</item>
....
</style>
回答by Nguyên Ph?m
You must set app:elevation="0dp"
in the android.support.design.widget.AppBarLayout
and then it works.
您必须app:elevation="0dp"
在 中设置android.support.design.widget.AppBarLayout
然后它才能工作。
<android.support.design.widget.AppBarLayout
app:elevation="0dp"... >
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@android:color/transparent"
app:popupTheme="@style/AppTheme.PopupOverlay" >
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
回答by YTerle
app:elevation="0dp"
but not
但不是
android:elevation="0dp"
worked for me on android L
在 android L 上为我工作
回答by shubham gupta
I have this same problem, and I have successfully solved this problem. All you have to do is just change the elevation to 0 floating point value in that activity in which you want to remove the elevation.
我有同样的问题,我已经成功解决了这个问题。您所要做的就是在要删除高程的活动中将高程更改为 0 浮点值。
If you want to change it in an activity called MyActivity.java
so you have to get the ActionBar
first.
如果您想在名为MyActivity.java
so的活动中更改它,则必须获得第ActionBar
一个。
First import the ActionBar
class
首先导入ActionBar
类
import android.support.v7.app.ActionBar;
after importing you have to initialize a variable of action bar and set its elevation to 0.
导入后,您必须初始化操作栏的变量并将其高程设置为 0。
private ActionBar toolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
.
.
toolbar=getSupportActionBar();
toolbar.setElevation(0);
.
.
}
回答by BYISHIMO Audace
For Xamarin Developers, please use : SupportActionBar.Elevation = 0;
for AppCompatActivity
or ActionBar.Elevation = 0;
for non-compat Activities
对于 Xamarin 开发人员,请使用 : SupportActionBar.Elevation = 0;
for AppCompatActivity
or ActionBar.Elevation = 0;
for non-compat Activity
回答by Rahul
Try This it helped me without changing theme . Put Your AppBarLayout inside any layout.Hope this will help you
试试这个它在不改变主题的情况下帮助了我。将您的 AppBarLayout 放在任何布局中。希望这对您有所帮助
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="false"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:layout_height="?attr/actionBarSize"
android:background="@color/white">
<ImageView
android:src="@drawable/go_grocery_logo"
android:layout_width="108dp"
android:layout_height="32dp" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
</RelativeLayout>