我正在编写一个将在嵌入式设备上的应用程序,我需要在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.
解决方法
XML中的小错误会导致非常奇怪的问题,
这些并不总是由构建过程准确报告.
当我可以在java中完成它时,我倾向于回避改变XML.
Java为您提供更多控制.
这些并不总是由构建过程准确报告.
当我可以在java中完成它时,我倾向于回避改变XML.
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")) );