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,111
  • AppCompatExample.zip
    9.9 KB · Views: 3,578
Last edited:

vfafou

Well-Known Member
Licensed User
Longtime User
Hello!
When I try to compile, I'm getting the following error:
B4X:
B4A version: 7.01
Parsing code.    (0.00s)
Compiling code.    (0.15s)
Compiling layouts code.    (0.02s)
Organizing libraries.    (0.00s)
Generating R file.    Error
C:\Users\VF\Desktop\AppCompatWithSlidingMenu\AppCompat\Objects\bin\extra\res3\res\values-v24\values-v24.xml:3: error: Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Borderless.Colored'.
C:\Users\VF\Desktop\AppCompatWithSlidingMenu\AppCompat\Objects\bin\extra\res3\res\values-v24\values-v24.xml:4: error: Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Colored'.
Any suggestion?

Thank you in advance!
 

little3399

Active Member
Licensed User
Longtime User
AppCompatWithDynamicMenuAndBadge DEMO program, can't seem to run? Are there any requirements for the Android version?

because it run once , it will go back to the os ...
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Now with a more colorful popup menu:

SS-2017-06-11_08.19.16.png


The color is set in the manifest editor:
B4X:
<style name="ToolbarMenu" parent="Base.ThemeOverlay.AppCompat.ActionBar">
    <item name="android:textColorPrimary">#fff</item>
    <item name="android:colorBackground">#0098FF</item>
   </style>

And is set with this code:
B4X:
Dim jo As JavaObject = ACToolBarLight1
Dim xl As XmlLayoutBuilder
jo.RunMethod("setPopupTheme", Array(xl.GetResourceId("style", "ToolbarMenu")))
 

Attachments

  • AppCompatWithDynamicMenuAndBadge.zip
    11.2 KB · Views: 3,776

Cassie

Member
Licensed User
Longtime User
Hi Guys,

any idea what could this error be "invalid resource directory name: C:\Users\Admin\Documents\Tutorials And Samples\B4a Samples\AppCompatWithDynamicMenuAndBadge\AppCompat\Objects\bin\extra\res2\res/values-b+sr+Latn"

Thanks
 

DonManfred

Expert
Licensed User
Longtime User
I'm using the latest version of B4A Version 7.01.
Talking about B4A you are right. But Erel said that the issue is related to the installed Build-Tools. It should be a NEWER one than you are using.

buildtools001.png

Install the newer 25.0.3.
DEINSTALL all versions <25
 
Status
Not open for further replies.
Top