[英]Removing bottom shadow on ActionBar - Android
我想禁用ActionBar
阴影,但只能在一个Activity
禁用。 如果我使用此代码,它将在整个应用程序中进行更改。
<style name="MyAppTheme" parent="android:Theme.Holo.Light">
<item name="android:windowContentOverlay">@null</item>
</style>
我试过这段代码,但它没有用
getSupportActionBar().setElevation(0);
有什么建议......?
您可以为此设置自己的活动样式:
<!-- Your main theme with ActionBar shadow. -->
<style name="MyAppTheme" parent="android:Theme.Holo.Light">
....
</style>
<!-- Theme without ActionBar shadow (inherits main theme) -->
<style name="MyNoActionBarShadowTheme" parent="MyAppTheme">
<item name="windowContentOverlay">@null</item>
<item name="android:windowContentOverlay">@null</item>
</style>
因此,在Manifest.xml中,您可以为所有活动设置不同的样式:
<!-- Activity with ActionBar shadow -->
<activity
android:name=".ShadowActivity"
android:theme="@style/MyAppTheme"/>
<!-- Activity without ActionBar shadow -->
<activity
android:name=".NoShadowActivity"
android:theme="@style/MyNoActionBarShadowTheme"/>
或者,您可以在onCreate()方法中以编程方式设置正确的主题:
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.MyNoActionBarShadowTheme);
super.onCreate(savedInstanceState);
//...
}
将app:elevation =“0dp”添加到appbarlayout,如下所示:
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="@style/AppTheme.AppBarOverlay"
app:elevation="0dp">
<android.support.v7.widget.Toolbar
android:id="@+id/home_tool_bar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
创建一个继承App主题的新主题:
<style name="MyAppTheme.NoShadow" parent="MyAppTheme">
<item name="android:windowContentOverlay">@null</item>
</style>
并让您的活动使用此主题。 在你的清单中:
<activity
android:name="...MyShadowlessActivity"
android:theme="@style/MyAppTheme.NoShadow" .../>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.