Question

This is my code:

params = new WindowManager.LayoutParams(
    WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
    WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
    PixelFormat.TRANSLUCENT);

wm = (WindowManager) getApplicationContext()
    .getSystemService(Context.WINDOW_SERVICE);

inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mTopView = (ViewGroup) inflater.inflate(R.layout.activity_invisible, null);

params.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
    | WindowManager.LayoutParams.FLAG_DIM_BEHIND
    | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
    | WindowManager.LayoutParams.FLAG_FULLSCREEN;

if (keep==true) {
    int value = brightnessIntent.getExtras().getInt("value");
    float v=value/255.0f;
    params.dimAmount=0;
    params.alpha=v;
    rl = (RelativeLayout) mTopView.findViewById(R.id.window);

    getWindow().setAttributes(params);
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,

    WindowManager.LayoutParams.FLAG_FULLSCREEN);
    wm.addView(mTopView, params);
}

The view still shows the status bar, mTopView is an overlay window. How do I get the overlay window to cover the entire screen? I don't want to "hide" the status bar, I want my activity to overlay onto it.

[EDIT] emphasized text I already have this in my onCreate() method:

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

And my manifest defines a style which features fullscreen.

SCREENSHOTS

enter image description here

This is how it is currently, I want the overlay to extend to the status bar too.

Était-ce utile?

La solution

All I had to do was this

params.flags=WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN| and the rest

This extends the overlay view over the status bar.

Autres conseils

This code from "Android Application 4 Development". you have to handle different android versions

 // Hiding the Action Bar for different android versions 
    if (Build.VERSION.SDK_INT < 16) {
        // Hide the Action Bar on Android 4.0 and Lower
         getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
     }else {
        // Hide the Action Bar on Android 4.1 and Higher
        View decorView = getWindow().getDecorView();
        int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
        decorView.setSystemUiVisibility(uiOptions);
        android.app.ActionBar actionBar = getActionBar();
        actionBar.hide();
     }

You can hide the status bar using two ways :

1) Define below line in your activity onCreate() method.

  requestWindowFeature(Window.FEATURE_NO_TITLE);

2)Define the theme at the application level not to show the status bar through out application as below:

<application android:label="@string/app_name"
  android:theme="@android:style/Theme.NoTitleBar.Fullscreen">

Try this..

   requestWindowFeature(Window.FEATURE_NO_TITLE);

it will not hide your status bar,your application will be cover full screen only status bar will be visible

           public class example extends Activity{

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);


    setContentView(R.layout.example);
}

}

And to hide the status bar

you can use

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

try this way

final WindowManager.LayoutParams params = new WindowManager.LayoutParams( 
WindowManager.LayoutParams.FLAG_FULLSCREEN, 
WindowManager.LayoutParams.FLAG_FULLSCREEN,                 
            WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,               
            WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
            PixelFormat.TRANSLUCENT);   

    WindowManager wm = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);    

    ViewGroup mTopView = (ViewGroup) App.inflater.inflate(R.layout.main, null);
    getWindow().setAttributes(params);
    wm.addView(mTopView, params);

To create always-top fullscreen overlay activity in Android:

public void onCreate(Bundle savedInstanceState) {       
 super.onCreate(savedInstanceState);        

 requestWindowFeature(Window.FEATURE_NO_TITLE);
 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
 getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);             
 getWindow().setBackgroundDrawableResource(android.R.color.transparent);
 getWindow().setFormat(PixelFormat.TRANSLUCENT);
 setContentView(R.layout.main);
 }

Translucent setting has to be enabled externally in xml manifest, otherwise it also didn't work.

 <item name="android:windowIsTranslucent">true</item>

You can hide the Title Bar by using:

public class MainActivity extends AppCompatActivity {  
@Override  
protected void onCreate(Bundle savedInstanceState) {  
    super.onCreate(savedInstanceState);  
    requestWindowFeature(Window.FEATURE_NO_TITLE);  
    getSupportActionBar().hide(); 
    setContentView(R.layout.activity_main);  
  }  
}  

and Get Full Screen by using:

public class MainActivity extends AppCompatActivity {  
@Override  
protected void onCreate(Bundle savedInstanceState) {  
    super.onCreate(savedInstanceState);  
     this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 
    setContentView(R.layout.activity_main);   
   }  
 }  

and also u can use parent="Theme.AppCompat.NoActionBar" in styles.xml

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top