<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
Hi @Alexander Stolte,
Just add this following code to your theme file (Tested on Oneplus 6):
B4X:<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
Use Manifest Editor to do so.
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="26"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.DarkTheme)
'End of default text.
Add it to your theme like this:How to add above code to manifest editor?
I've tried to add the code to manifest editor like below:
But the results are still not right. (tested on Xiaomi MI 8)B4X:'This code will be applied to the manifest file during compilation. 'You do not need to modify it in most cases. 'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136 AddManifestText( <uses-sdk android:minSdkVersion="5" android:targetSdkVersion="26"/> <supports-screens android:largeScreens="true" android:normalScreens="true" android:smallScreens="true" android:anyDensity="true"/> <item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>) SetApplicationAttribute(android:icon, "@drawable/icon") SetApplicationAttribute(android:label, "$LABEL$") CreateResourceFromFile(Macro, Themes.DarkTheme) 'End of default text.
View attachment 75210 View attachment 75211
SetApplicationAttribute(android:theme, "@style/CustomTheme")
CreateResource(values, theme.xml,
<resources>
<style name="CustomTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
</style>
</resources>
)
Add it to your theme like this:
B4X:SetApplicationAttribute(android:theme, "@style/CustomTheme") CreateResource(values, theme.xml, <resources> <style name="CustomTheme" parent="Theme.AppCompat.Light.NoActionBar"> <item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item> </style> </resources> )
Generating R file. Error
res\values\theme.xml:3: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.NoActionBar'.
res\values\theme.xml:4: error: Error: No resource found that matches the given name: attr 'android:windowLayoutInDisplayCutoutMode'.
Use latest android.jar and add this following code to your activity if you want to use AppCompat.Thanks Brandsum for your reply, but i get this error after add your code to manifest editor:
B4X:Generating R file. Error res\values\theme.xml:3: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.NoActionBar'. res\values\theme.xml:4: error: Error: No resource found that matches the given name: attr 'android:windowLayoutInDisplayCutoutMode'.
Did i miss something?
#Extends: android.support.v7.app.AppCompatActivity
Use latest android.jar and add this following code to your activity if you want to use AppCompat.
You can change Theme.AppCompat.Light.NoActionBar as per your need. Like Theme.holo.lightB4X:#Extends: android.support.v7.app.AppCompatActivity
NOTE: android:windowLayoutInDisplayCutoutMode provided by the APIs in Android Pie 9.0.
Sub GetRealSize As LayoutValues
Dim lv As LayoutValues
Dim p As Phone
If p.SdkVersion >= 17 Then
Dim ctxt As JavaObject
ctxt.InitializeContext
Dim display As JavaObject = ctxt.RunMethodJO("getSystemService", Array("window")).RunMethod("getDefaultDisplay", Null)
Dim point As JavaObject
point.InitializeNewInstance("android.graphics.Point", Null)
display.RunMethod("getRealSize", Array(point))
lv.Width = point.GetField("x")
lv.Height = point.GetField("y")
Else
lv.Width = 100%x
lv.Height = 100%y
End If
lv.Scale = 100dip / 100
Return lv
End Sub
Sub Activity_Create(FirstTime As Boolean)
Dim jo As JavaObject = Activity
jo.RunMethod("setSystemUiVisibility", Array As Object(5894)) '3846 - non-sticky
Dim lv As LayoutValues = GetRealSize
Dim jo As JavaObject = Activity
jo.RunMethod("setBottom", Array(lv.Height))
jo.RunMethod("setRight", Array(lv.Width))
Activity.Height = lv.Height
Activity.Width = lv.Width
Activity.LoadLayout("Layout1")
End Sub
not working on my Xiaomi MI 8 (Android 8), but when i tried on Genymotion with Android 9 + simulated top notch and its working for the shortEdges
NOTE: android:windowLayoutInDisplayCutoutMode provided by the APIs in Android Pie 9.0.
As per this documentation https://developer.android.com/guide/topics/display-cutout/but return the wrong display size if i change the value to "default"/"never" like the screenshots
If you use never and want to get the correct display height without that notch covered area then you have to deduct the notch height from the actual height.How do i get the correct display size after black bar that cover the notch added?
If you use never and want to get the correct display height without that notch covered area then you have to deduct the notch height from the actual height.
Check this to get the notch area height: https://developer.android.com/reference/android/view/WindowInsets#getDisplayCutout()
Could you or anyone here can help me to modify this project to get the correct display size if the phone has the notch?