0

J'ai essayé de cacher la barre de notification, ce qui rend mon application plein écran:Android Comment cacher la barre de notification

J'ai essayé quelques exemples de codes, mais ils ne fonctionnent pas, il y avait:

1 # android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen"

2 #

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

     setContentView(R.layout.activity_main); 

Voir ci-dessous pour les erreurs de LogCat: ...

ici est mon code, merci pour votre aide:

MainActivity

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> 

styles.xml

<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> 

** LogCat Log: l'échantillon 2 # **

06-26 11:18:01.753: D/AndroidRuntime(19490): Shutting down VM 
06-26 11:18:01.753: W/dalvikvm(19490): threadid=1: thread exiting with uncaught exception (group=0x411172a0) 
06-26 11:18:01.753: E/AndroidRuntime(19490): FATAL EXCEPTION: main 
06-26 11:18:01.753: E/AndroidRuntime(19490): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.brazilapps/com.example.brazilapps.MainActivity}: java.lang.NullPointerException 
06-26 11:18:01.753: E/AndroidRuntime(19490): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110) 
06-26 11:18:01.753: E/AndroidRuntime(19490): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135) 
06-26 11:18:01.753: E/AndroidRuntime(19490): at android.app.ActivityThread.access$700(ActivityThread.java:140) 
06-26 11:18:01.753: E/AndroidRuntime(19490): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237) 
06-26 11:18:01.753: E/AndroidRuntime(19490): at android.os.Handler.dispatchMessage(Handler.java:99) 
06-26 11:18:01.753: E/AndroidRuntime(19490): at android.os.Looper.loop(Looper.java:137) 
06-26 11:18:01.753: E/AndroidRuntime(19490): at android.app.ActivityThread.main(ActivityThread.java:4921) 
06-26 11:18:01.753: E/AndroidRuntime(19490): at java.lang.reflect.Method.invokeNative(Native Method) 
06-26 11:18:01.753: E/AndroidRuntime(19490): at java.lang.reflect.Method.invoke(Method.java:511) 
06-26 11:18:01.753: E/AndroidRuntime(19490): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038) 
06-26 11:18:01.753: E/AndroidRuntime(19490): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805) 
06-26 11:18:01.753: E/AndroidRuntime(19490): at dalvik.system.NativeStart.main(Native Method) 
06-26 11:18:01.753: E/AndroidRuntime(19490): Caused by: java.lang.NullPointerException 
06-26 11:18:01.753: E/AndroidRuntime(19490): at com.example.brazilapps.MainActivity.onCreate(MainActivity.java:46) 
06-26 11:18:01.753: E/AndroidRuntime(19490): at android.app.Activity.performCreate(Activity.java:5188) 
06-26 11:18:01.753: E/AndroidRuntime(19490): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094) 
06-26 11:18:01.753: E/AndroidRuntime(19490): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074) 
06-26 11:18:01.753: E/AndroidRuntime(19490): ... 11 more 

Répondre

0

Tout d'abord, avez-vous changé le nom de la mise en page dans l'échantillon à votre nom de mise en page? Avez-vous essayé de cette façon?

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

    setContentView(R.layout.activity_main); // not R.layout.main 

Ensuite, que fait ce code? Je pense que ça ne cache absolument rien

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

Désolé, oui, le R.layout.activity_main a été réglé à la bonne. J'ai ajouté mon journal LogCat en utilisant l'exmaple # 2. Peut-être que cela peut aider à montrer l'erreur. Merci –

Questions connexes