Is there a Action Bar in B4A?

rasaliad

Member
Licensed User
Longtime User
Hi All,

How can I invoke a Action Bar, like Google recomend to use it. Is there an Action Bar in B4A?

I Attach a image with a google action bar example.

TIA

Rafael Liriano

ActionBar.png
 

JdV

Active Member
Licensed User
Longtime User
Hello

I have a program that has a single menu item which is created using the following command:

Activity.AddMenuItem2("Help", "RunHelp", LoadBitmap(File.DirAssets, "helpicon.png"))

On Android 2.x pressing the menu button it shows the menu item with the graphic.

On my Galaxy Tab running Android 3 it shows an icon representing a menu in the 'Action Bar'. Pressing on that it shows a single menu item labelled "Help" but it doesn't show the icon.

Is there a particular way in which menus should be created in BASIC4Android in order to add them to the Action Bar?

Regards

Joe
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Yes. You should edit the manifest file and change the minSdkVersion to:
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="11" />

Don't forget to mark "Do not overwrite manifest file".
The menu will now appear in the top right corner:
SS-2011-11-23_09.57.19.png


See this link for another required step: http://www.b4x.com/forum/showpost.php?p=74160&postcount=16
 
Upvote 0

Inman

Well-Known Member
Licensed User
Longtime User
Nice! Is it possible to add other items on action bar as well, like in this screen shot where Box Office, Theaters, Upcoming etc...are located?

Q4aRP.jpg
 
Upvote 0

JdV

Active Member
Licensed User
Longtime User
Hello

I have created a simple program that contains only the following code:

B4X:
Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("Test")
   Activity.AddMenuItem("Help and Information","HelpMenu")
End Sub


The manifest file contains the edited line:
<uses-sdk android:minSdkVersion="11" />

When the app first loads on a tablet it doesn't display the menu icon. The icon only appears if the orientation is changed.

I also noticed this happens sometimes on the emulator.

Is this an Android wide issue?

Regards

Joe
 
Upvote 0

JdV

Active Member
Licensed User
Longtime User
Erel

I have tried that and the results are the same, namely that the menu icon doesn't appear when the app first runs. I have attached a test app.

Is this a bug?

Regards

Joe
 

Attachments

  • MenuTest.zip
    5.9 KB · Views: 406
Last edited:
Upvote 0

JdV

Active Member
Licensed User
Longtime User
Erel

I use a Samsung Galaxy Tab 10.1 (Android 3.1). It also has the same problem running it in an Android 3.1 emulator.

It's always the first time the app runs that it doesn't display the menu icon. If I back out of the app then re-run it the icon appears.

If you go into Settings -> Applications and do a 'Force Stop' on it, then re-run the app the problem reoccurs for me.

If it's working OK for you then I am at a loss to explain it! :sign0163:

Incidentally, what JDK are you using? I'm using 1.6.0_27. (I have tried it with android.jar from android-8 and android-14 with the same results.)

Regards

Joe
 
Upvote 0

JdV

Active Member
Licensed User
Longtime User
Erel

According to the Android SDK manager I am up to date with pretty much everything. Under "Android 2.2 (API 8)" it says I have the Samsung Galaxy Tab add on installed - I don't know if that makes any difference since I have set B4A to point to the Android.jar file in the android-14 folder.

Is there anything else you can think of that I should check?

Regards

Joe
 
Upvote 0

JdV

Active Member
Licensed User
Longtime User
Are other users with Android 3.x experience this issue?

I have only tested the app myself and supplied the files to you. Apart from the Galaxy Tab I have tested it on emulators on 2 different PCs.

Would you be able to compile the program and send me the APK file to see if that makes a difference?

Regards

Joe
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Now it happened here as well. Which is a good thing, as I was able to fix it with the reflection library:
B4X:
   Activity.LoadLayout("MenuTest")
   Activity.AddMenuItem("Help","HelpMenu")
   
   Dim r As Reflector
   Dim ver As Int
   ver = r.GetStaticField("android.os.Build$VERSION", "SDK_INT")
   If ver >= 11 Then
      r.Target = r.GetActivity
      r.RunMethod("invalidateOptionsMenu")
   End If
 
Upvote 0

JdV

Active Member
Licensed User
Longtime User
Erel

Thanks for that.

Does that suggest it's an Android OS bug?

Regards

Joe
 
Upvote 0
Top