android – WindowActivityBar = false无法正常工作

前端之家收集整理的这篇文章主要介绍了android – WindowActivityBar = false无法正常工作前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在编写一个将在嵌入式设备上的应用程序,我需要在TitleBar和ContentOverlay旁边删除ActionBar.
我找到了一个解决方案并在我的样式中插入以下内容
  1. <style name="NoActionBar" parent="@android:style/Theme.Holo.Light">
  2. <item name="android:windowActionBar">false</item>
  3. <item name="android:windowNoTitle">true</item>
  4. <item name="android:windowFullscreen">true</item>
  5. <item name="android:windowContentOverlay">@null</item>
  6. </style>

并在AndroidManifest中将该行添加到我的活动中:

  1. android:theme="@style/NoActionBar"

最后我没有标题栏,没有内容覆盖,但ActionBar仍然存在.请指教.我使用android:theme =“@ android:style / Theme.Holo.Light”,我的targetSdkVersion是18.

解决方法

XML中的小错误会导致非常奇怪的问题,
这些并不总是由构建过程准确报告.
当我可以在java中完成它时,我倾向于回避改变XML.
Java为您提供更多控制.
  1. programmatically remove action bar
  2. ----------------------------------
  3. from normal activity
  4.  
  5. getActionbar().hide();
  6. getActionbar().show();
  7.  
  8. if your using support activity
  9.  
  10. getSupportActionBar().hide();
  11. getSupportActionBar().show();
  12.  
  13. and from the Fragment you can do it
  14.  
  15. getActivity().getActionbar().hide();
  16. getActivity().getActionbar().show();
  17.  
  18. remove title bar
  19. ----------------
  20.  
  21. public class ActivityName extends Activity {
  22. @Override
  23. public void onCreate(Bundle savedInstanceState) {
  24. super.onCreate(savedInstanceState);
  25. // remove title
  26. requestWindowFeature(Window.FEATURE_NO_TITLE);
  27. getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
  28. setContentView(R.layout.main);
  29. }
  30. }
  31.  
  32. ActionBar ContentOverlay
  33. ------------------------
  34. 1) Request for actionbar overlay programmatically by calling
  35.  
  36. getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
  37.  
  38. // this 'requestFeature()' must be requested from your activity 'onCreate()' method
  39. // before calling for 'setContentView(R.layout.my_layout)':
  40. 2) set the actionbar color by calling setBackgroundDrawable() like so:
  41. getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#00212121")) );

猜你在找的Android相关文章