Android Code Snippet targetSdkVersion 35 and opting out of edge-to-edge enforcement

Starting from B4A v13.4, the default themes (Themes.LightTheme / Themes.DarkTheme) already include the snippet that opts out of edge-edge. You only need this if you use a customize theme.

The recommended targetSdkVersion is presently 34, however if you like to experiment with v35 then your app will be enforced to become edge-to-edge. This is a feature that will be mandatory at some point in the future (maybe 2 years from now) and it goes together with other upcoming requirements of handling content resizes. For now I recommend opting out of this enforcement.

This is done by:
1. Download "android sdk platform 35" with B4A Sdk Manager.
2. Configure the IDE to use android.jar from platforms\android-35.
3. Add to manifest editor:
B4X:
SetApplicationAttribute(android:theme, "@style/LightTheme")
CreateResource(values, theme.xml,
<resources>
    <style
        name="LightTheme" parent="@android:style/Theme.Material.Light">
       <item name="android:actionMenuTextAppearance">@style/LowerCaseMenu</item>
       <item name="android:windowOptOutEdgeToEdgeEnforcement">true</item>
    </style>
     <style name="LowerCaseMenu" parent="android:TextAppearance.Material.Widget.ActionBar.Menu">
        <item name="android:textAllCaps">false</item>
    </style>
</resources>
)
4. Make sure to remove this line:
B4X:
CreateResourceFromFile(Macro, Themes.LightTheme)

This replaces the default Theme.LightTheme with a similar theme that includes the option to opt out of the edge to edge enforcement.
 
Last edited:

Pendrush

Well-Known Member
Licensed User
Longtime User
I'm using API 35 as target with B4A in a small private app (not published on Play store) for at least 6-7 moths, only with <item name="android:windowOptOutEdgeToEdgeEnforcement">true</item>.
No problem so far.
 

Mehrzad238

Active Member
If you need to use CustomListView or RecyclerView, the last item might not be accessible; to solve this issue, just add a padding on the bottom (50dip would be enough) that will do the job.
Even the android itself suggests this method.
 

Attachments

  • photo_2025-05-22_19-36-53.jpg
    photo_2025-05-22_19-36-53.jpg
    49.8 KB · Views: 467
  • photo_2025-05-22_19-36-52.jpg
    photo_2025-05-22_19-36-52.jpg
    51.4 KB · Views: 469

Johan Hormaza

Well-Known Member
Licensed User
Longtime User
This means that it will no longer be necessary to use this configuration to stretch the Activity.


B4X:
    Dim jo As JavaObject
    Dim window As JavaObject = jo.InitializeContext.RunMethod("getWindow", Null)
    window.RunMethod("addFlags", Array(Bit.Or(0x00000200, 0x08000000)))
    Dim view As JavaObject = window.RunMethodJO("getDecorView",Null)
    view.RunMethod("setSystemUiVisibility",Array(Bit.Or(0x00002000,view.RunMethod("getSystemUiVisibility",Null)))) 'Light style with black icons and text
    Activity.Height = Activity.Height + 80dip
 

Scantech

Well-Known Member
Licensed User
Longtime User
so with mandatory edge to edge, do we need to make the adjustments or will the future version b4a fix this?
 

asales

Expert
Licensed User
Longtime User
I just change the SDK target to 35 in the manifest, with the B4A 13.30 beta, and this behaviour is showing automatically in an emulator with Android 15.
 

Filippo

Expert
Licensed User
Longtime User
Hi,

how to change the color of “actionbar” and “navigationBarColor” when using the manifest script from the first post?
If you add this script, then the colors cannot be changed.
B4X:
SetApplicationAttribute(android:theme, "@style/LightTheme")
CreateResource(values, colors.xml,
<resources>
    <color name="actionbar">#ff039be5</color>
   <color name="statusbar">#ff006db3</color>
   <color name="textColorPrimary">#ffffffff</color>
   <color name="navigationBar">#ff006db3</color>
</resources>
)
CreateResource(values, theme.xml,
<resources>
    <style name="LightTheme" parent="@android:style/Theme.Material.Light">
        <item name="android:colorPrimary">@color/actionbar</item>
        <item name="android:colorPrimaryDark">@color/statusbar</item>
        <item name="android:textColorPrimary">@color/textColorPrimary</item>
        <item name="android:navigationBarColor">@color/navigationBar</item>
    </style>
</resources>
)
 

mcqueccu

Well-Known Member
Licensed User
Longtime User
I got an email from Google that forces the developers to upgrade to SDK 35 by Aug 30, 2025:

"App must target Android 15 (API level 35) or higher"
The Post was written before B4A v13.40 was released. Starting from v13.40 Recommended is targetSdkVersion is 35

When using B4A 13.40 It will warn you the recommended is 35
 

tagwato

Member
Licensed User
Longtime User
Let's say I want to opt IN (because Google will soon remove the opt-out option).
And, let's say I want to adjust for the bars insets (overlapping areas) in the activity as a whole.
I could use a solution like the one proposed by MrCoder in this thread: https://www.b4x.com/android/forum/threads/problem-with-android-version-15-and-higher.166267/ (page 2 has a complete example).
It is very clever. Notice that it's using getInsetsIgnoringVisibility() instead of the getInsets() method. That makes sense, since everything Is running in Activity.create, so the UI probably isn't built yet.

However, I have doubts. It seems to assume that the navigation bar and status bar will be permanently visible afterward. But... Is that 'always true? Can we be sure that the navigation bar is ALWAYS visible when "edge to edge enforcement" is enabled?
Or could there be a specific device that, by default, puts the bars in TRANSIENT visibility mode (SWIPE), even when running API 'level 35 and "edge to edge enforcement" enabled?
If so, the getInsetsIgnoringVisibility() method will return insets > 0, the adjustments will be applied and the app will stop using the overlapped area. However, the bar will only appear momentarily on the screen. To avoid wasting that area, perhaps it would be better to detect this kind of situation and only make the adjustment If the bars are configured by default (in the system) to be ALWAYS visible.
But I haven't found a way to 'detect this configuration. So, my questions are:
  • How to know if the system bars default setting configured in the system is ALWAYS visible? (especially the navigation bar)
  • Or there are any other workaround ?
 
Top