微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android – WindowActivityBar = false无法正常工作

我正在编写一个将在嵌入式设备上的应用程序,我需要在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为您提供更多控制.
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")) );

原文地址:https://www.jb51.cc/android/315148.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐