我正在编写一个将在嵌入式设备上的应用程序,我需要删除与TitleBar和ContentOverlay一起的ActionBar。 我找到了一个解决方案并在我的样式中插入以下内容:
<style name="NoActionBar" parent="@android:style/Theme.Holo.Light">
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>
并在AndroidManifest中将该行添加到我的活动中:
android:theme="@style/NoActionBar"
最后我没有标题栏,没有内容覆盖,但ActionBar仍然存在。请指教。我使用android:theme="@android:style/Theme.Holo.Light"
而我的targetSdkVersion是18。
答案 0 :(得分:1)
XML中的小错误可能会导致非常奇怪的问题 这些并不总是由构建过程准确报告 我倾向于回避改变XML,当我可以在java中做到这一点 Java为您提供更多控制。
programmatically remove action bar
----------------------------------
from normal activity
getActionbar().hide();
getActionbar().show();
if your using support activity
getSupportActionBar().hide();
getSupportActionBar().show();
and from the Fragment you can do it
getActivity().getActionbar().hide();
getActivity().getActionbar().show();
remove title bar
----------------
public class ActivityName extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// remove title
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
}
}
ActionBar ContentOverlay
------------------------
1) Request for actionbar overlay programmatically by calling
getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
// this 'requestFeature()' must be requested from your activity 'onCreate()' method
// before calling for 'setContentView(R.layout.my_layout)':
2) set the actionbar color by calling setBackgroundDrawable() like so:
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#00212121")) );
答案 1 :(得分:-1)
尝试更改您的风格的父母:
parent="@android:style/Theme.Holo.Light.NoActionBar"
示例
<style name="NoActionBar" parent="@android:style/Theme.Holo.Light.NoActionBar">
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>