Android Example AppCompat with ToolBar - minimal example

Status
Not open for further replies.
In most cases AppCompat is no longer needed and will only make things more complicated.
B4XPages example with dynamic menu: https://www.b4x.com/android/forum/threads/b4x-menu-badges.133301/

appcompat.gif




The project attached uses the powerful AppCompat library to replace the built-in ActionBar with a more robust ToolBar.

The NavigationItemClick event is raised when the icon is clicked.

You can set ToolbarHelper.ShowUpIndicator = True to show an up arrow instead. It will raise the same event.

SS-2017-05-24_12.20.07.png


You can change the toolbar color in the manifest editor.

Sliding side menu + dynamic menu items: https://www.b4x.com/android/forum/threads/appcompat-with-toolbar-minimal-example.79896/#post-509530

SS-2017-06-08_17.06.06.png


Example based on B4ADrawer: https://www.b4x.com/android/forum/threads/class-b4adrawer-sliding-drawer.97828/#post-616518

b4adrawer.gif



Edit: depending on your Android SDK version, you might get this error:

java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/arch/core/executor/ArchTaskExecutor;

The solution is to add this line in the main activity:
B4X:
#AdditionalJar: androidx.arch.core:core-runtime
 

Attachments

  • upload_2017-5-24_12-18-26.png
    upload_2017-5-24_12-18-26.png
    7.3 KB · Views: 4,299
  • AppCompatExample.zip
    9.9 KB · Views: 98
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
Updated first example with targetSdkVersion 35. The updated manifest:
B4X:
SetApplicationAttribute(android:theme, "@style/MyAppTheme")

CreateResource(values, theme.xml,
<resources>
    <style name="MyAppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">#0098FF</item>
        <item name="colorPrimaryDark">#007CF5</item>
        <item name="colorAccent">#AAAA00</item>
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="android:windowOptOutEdgeToEdgeEnforcement">true</item>
    </style>
</resources>
)
 
Status
Not open for further replies.
Top