gpt4 book ai didi

android - 以编程方式删除操作栏阴影

转载 作者:IT老高 更新时间:2023-10-28 23:30:25 28 4
gpt4 key购买 nike

如何从 java 代码中删除操作栏的阴影?

如果我从样式中删除它工作正常。

<style name="MyTheme" parent="Theme.Sherlock">
....
<item name="windowContentOverlay">@null</item>
<item name="android:windowContentOverlay">@null</item>
....
</style>

但我需要从 java 代码中动态删除和添加它。

最佳答案

无法以编程方式设置 windowContentOverlay 属性的值。但是您可以定义两种不同的主题,一种用于带有可见 ActionBar 阴影的 Activity ,另一种用于其他主题:

<!-- Your main theme with ActionBar shadow. -->
<style name="MyTheme" parent="Theme.Sherlock">
....
</style>

<!-- Theme without ActionBar shadow (inherits main theme) -->
<style name="MyNoActionBarShadowTheme" parent="MyTheme">
<item name="windowContentOverlay">@null</item>
<item name="android:windowContentOverlay">@null</item>
</style>

现在您可以将它们设置为 AndroidManifest.xml 中的 Activity :

<!-- Activity with ActionBar shadow -->
<activity
android:name=".ShadowActivity"
android:theme="@style/MyTheme"/>

<!-- 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);

//...
}

关于android - 以编程方式删除操作栏阴影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19922078/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com