Android如何隐藏通知栏

Android如何隐藏通知栏,android,android-activity,android-fragments,android-theme,android-notification-bar,Android,Android Activity,Android Fragments,Android Theme,Android Notification Bar,我一直试图隐藏通知栏,使我的应用程序全屏显示: 我尝试了一些示例代码,但它们不起作用,有: 1#android:theme=“@android:style/theme.Holo.NoActionBar.Fullscreen” 2# 有关logcat错误,请参见以下内容: 这是我的代码,谢谢你的帮助: main活动 import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v7

我一直试图隐藏通知栏,使我的应用程序全屏显示:

我尝试了一些示例代码,但它们不起作用,有:

1#
android:theme=“@android:style/theme.Holo.NoActionBar.Fullscreen”

2#

有关logcat错误,请参见以下内容:

这是我的代码,谢谢你的帮助:

main活动

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends ActionBarActivity {

    public static final String TAG = MainActivity.class.getSimpleName();

    ActionBar actionBar;

    // Declare Tab Variable
    ActionBar.Tab Tab1, Tab2, Tab3;
    Fragment fragmentTab1 = new FragmentTab1(); 
    Fragment fragmentTab2 = new FragmentTab2();
    Fragment fragmentTab3 = new FragmentTab3();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        //Hide Action Bar
        actionBar = getSupportActionBar();              
        // Hide Actionbar Icon
        actionBar.setDisplayShowHomeEnabled(true);
        // Hide Actionbar Title
        actionBar.setDisplayShowTitleEnabled(true);
        // Create Actionbar Tabs
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

        // Set Tab Icon and Titles
        Tab1 = actionBar.newTab().setText("Asian");//.setIcon(R.drawable.tab1);
        Tab2 = actionBar.newTab().setText("Euro");
        Tab3 = actionBar.newTab().setText("Black");

        // Set Tab Listeners
        Tab1.setTabListener(new TabListener(fragmentTab1));
        Tab2.setTabListener(new TabListener(fragmentTab2));
        Tab3.setTabListener(new TabListener(fragmentTab3));

        // Add tabs to actionbar
        actionBar.addTab(Tab1);
        actionBar.addTab(Tab2);
        actionBar.addTab(Tab3);

    }//-----end onCreate

//Action bar of AppCombat -------------------------------------------------------------------------
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}//--end body
themes.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="customTheme" parent="android:Theme"> 
        <item name="android:windowTitleBackgroundStyle">@style/WindowTitleBackground</item> 
        <item name="android:windowFullscreen">true</item>   
    </style> 
</resources>
<resources>

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light">
        <item name="android:windowNoTitle">true</item>
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
        -->
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>

    <style name="myImageView">
        <!-- 3dp so the background border to be visible -->
        <item name="android:padding">3dp</item>
        <item name="android:background">@drawable/image_border</item>
        <item name="android:scaleType">fitCenter</item>
    </style>


    <style name="WindowTitleBackground">
        <item name="android:background">@color/titlebackgroundcolor</item>
    </style>

</resources>

首先,您是否已将示例中的布局名称更改为您的布局名称?你用这种方法试过吗

requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.activity_main); // not R.layout.main
那么这段代码在做什么?我想这绝对不是在隐瞒什么

//Hide Action Bar
    actionBar = getSupportActionBar();              
    // Hide Actionbar Icon
    actionBar.setDisplayShowHomeEnabled(true);
    // Hide Actionbar Title
    actionBar.setDisplayShowTitleEnabled(true);

抱歉,是的,R.layout.activity_main已设置为正确的。我使用exmaple 2添加了我的LogCat日志。也许这有助于显示错误。谢谢
requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.activity_main); // not R.layout.main
//Hide Action Bar
    actionBar = getSupportActionBar();              
    // Hide Actionbar Icon
    actionBar.setDisplayShowHomeEnabled(true);
    // Hide Actionbar Title
    actionBar.setDisplayShowTitleEnabled(true);