Reputation: 2660
On my device I can successfully hide the status bar by doing the following:
In my manifest I add the following:
<activity
android:name=".SomeActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen"
/>
then in my styles:
<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="@style/Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>
On my device (Samsung J7 Pro running Android 9), this is the result:
As you can see, the status bar and the action bar is hidden. But if I run this on a Huawei P20 Lite, this is the result I get:
At the top there is a black bar where the status bar will be.
Why is this happening?
Upvotes: 1
Views: 458
Reputation: 4371
Create a values-v28
folder parallel to values
folder.
Copy the theme content in new styles.xml
file and add <item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="@style/Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
</style>
Also, in Activity class add the following
public class MyActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.my_activity);
}
}
Upvotes: 4
Reputation: 56
Please check this link making apps notch friendly. Apparently it is happening because the device has a notch.
Upvotes: 2