Android Tutorial Material Design 3 - Using a ToolBar as ActionBar

corwin42

Expert
Licensed User
Longtime User
Ok i was reluctant to update the sdk(appcompact).But this i decided to go through but BANG.Any compile with the appcompact lib gives me a black screen.Is there a possible reason.
NB:I just tried modifying the theme file as stated but the pb persists.

Do you get any errors? Never had a "black screen" without any other error. Do you see something in the unfiltered logs (connected via USB)?
 

jahswant

Well-Known Member
Licensed User
Longtime User
The activity doesn't even start at all.Just a black screen with no compilation error.
 

corwin42

Expert
Licensed User
Longtime User
The activity doesn't even start at all.Just a black screen with no compilation error.
Just read the section about support library 22.1 and above in OP of this thread. I'm 100% sure that is the problem.

btw: A "black screen" is not the same as "Activity is not starting at all". Thats the problem with such issue reports. Most people don't write exactly what they see or have done. And it is very time consuming for us library developers to guess what the problem may be.
 

thedesolatesoul

Expert
Licensed User
Longtime User
Also a lot of users report a black screen even when there is a perfectly debuggable crash and the stack trace is in the logs.
As google iterates through their libraries i've seen there mainly to be three reasons:
1. The android.jar version B4A refers to
2. The version of the support libs
3. The version of the resource files (may be compatible with an older version but not new one)
 

Anser

Well-Known Member
Licensed User
Longtime User
I understand that the Click on the UpArrowIndicator does not work without an overflow menu on the ActionBar. In other words, the Click on the UpArrowIndicator works only if there is an overflow menu on the ToolBar. How to overcome this issue ? Is there any specific reason for that ? or am I missing something ?

After spending so much time, I found that the work around to solve this problem is to add an OverFlow Menu, but it doesn't seem to be an elegant solution.

B4X:
ABHelper.Initialize
ABHelper.ShowUpIndicator = True
 
' This will create the OverFlow Menu. If this is not added then the Back button on the left side of the Toolbar does not work
Activity.AddMenuItem("Go Back", "Menu_GoBack")

'I Capture the UpIndicator Click using the below given Sub. Unfortunately this does not get executed if I don't add an overflow Menu to the ActionBar
Sub Activity_ActionBarHomeClick
    Activity.Finish
End Sub

'Capture the click on the OverFlow Menu Item and then re-direct to Activity_ActionBarHomeClick
Sub Menu_GoBack_Click
    Activity_ActionBarHomeClick
End Sub

I am herewith pasting the whole code, so that someone can verify whether I am doing it in a wrong way
B4X:
#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region
#Extends: android.support.v7.app.ActionBarActivity

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private ActionBar As ACToolBarLight
    Private lvCallsList As ListView
 
    Dim AC As AppCompat
    Dim ABHelper As ACActionBar 
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("CallsList")
 
    'Set the ToolBar (it is called ActionBar in the layout file) as the ActionBar of this activity.
    ActionBar.SetAsActionBar 
 
    'Set Title and Subtitle for the ToolBar
    ActionBar.Title = "My Title"
    ActionBar.SubTitle = "My SubTitle"
 
    ' Set the Toolbar Shadow
    AC.SetElevation(ActionBar, 8dip)
 
    ABHelper.Initialize
    ABHelper.ShowUpIndicator = True
 
   ' This will create the OverFlow Menu. If this is not added then the Back button 
   ' on the left side of the Toolbar is not working
    Activity.AddMenuItem("Go Back", "Menu_GoBack")

End Sub

Sub Activity_Resume
 
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Activity_ActionBarHomeClick
    Activity.Finish
End Sub

Sub Menu_GoBack_Click
    Activity_ActionBarHomeClick
End Sub

I don't know whether I could ask doubt in this thread, as I feel that this query is related to this Material Design - Using a ToolBar as ActionBar, I am posting it here.

Any help would be appreciated

Thanks & Regards

Anser
 

corwin42

Expert
Licensed User
Longtime User
The answer is in the last post on the second page of this thread. Use ToolbarXXX.InitMenuListener and the NavigationitemClicked event of the Toolbar.
 

ivan.tellez

Active Member
Licensed User
Longtime User
Hi, this is a really great tutorial.

What is the better option to implement a side menu/drawer whit this toolbar?

Also, when you use:

B4X:
ABHelper.ShowUpIndicator = True

Is there a way to animate the icon?

Thanks
 

ArminKH

Well-Known Member
hi @corwin42
is there any solution to achive to following code ?
B4X:
For i = 0 To AppCombatToolbar.NumberOfViews -1
        AppCombatToolbar.GetView(i).Left = 100%x - AppCombatToolbar.GetView(i).Left - AppCombatToolbar.GetView(i).Width
    Next
this code not worked because the layout of view is not available
i want to reverse the dimension of all view's which is added to toolbar for adjusting the toolbars for write to left languages
tnx
 

fishwolf

Well-Known Member
Licensed User
Longtime User
with the example in page 1 the app doen't start and don't see errors from b4x

from monitor i have this error,

how to i can fix ?

thanks

B4X:
08-13 16:25:04.726: I/B4A(3002): ~e:java.lang.RuntimeException: Unable to start activity ComponentInfo{de.amberhome.appcompat.toolbarexample1/de.amberhome.appcompat.toolbarexample1.main}: java.lang.IllegalArgumentException: AppCompat does not support the current theme features
08-13 16:25:04.726: I/B4A(3002): ~e:   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
08-13 16:25:04.726: I/B4A(3002): ~e:   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
08-13 16:25:04.726: I/B4A(3002): ~e:   at android.app.ActivityThread.access$600(ActivityThread.java:130)
08-13 16:25:04.726: I/B4A(3002): ~e:   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
08-13 16:25:04.726: I/B4A(3002): ~e:   at android.os.Handler.dispatchMessage(Handler.java:99)
08-13 16:25:04.726: I/B4A(3002): ~e:   at android.os.Looper.loop(Looper.java:137)
08-13 16:25:04.726: I/B4A(3002): ~e:   at android.app.ActivityThread.main(ActivityThread.java:4745)
08-13 16:25:04.726: I/B4A(3002): ~e:   at java.lang.reflect.Method.invokeNative(Native Method)
08-13 16:25:04.726: I/B4A(3002): ~e:   at java.lang.reflect.Method.invoke(Method.java:511)
08-13 16:25:04.726: I/B4A(3002): ~e:   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
08-13 16:25:04.726: I/B4A(3002): ~e:   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-13 16:25:04.726: I/B4A(3002): ~e:   at dalvik.system.NativeStart.main(Native Method)
08-13 16:25:04.726: I/B4A(3002): ~e:Caused by: java.lang.IllegalArgumentException: AppCompat does not support the current theme features
08-13 16:25:04.726: I/B4A(3002): ~e:   at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:363)
08-13 16:25:04.726: I/B4A(3002): ~e:   at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:237)
08-13 16:25:04.726: I/B4A(3002): ~e:   at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:111)
08-13 16:25:04.726: I/B4A(3002): ~e:   at de.amberhome.appcompat.toolbarexample1.main.onCreate(main.java:59)
08-13 16:25:04.726: I/B4A(3002): ~e:   at android.app.Activity.performCreate(Activity.java:5008)
08-13 16:25:04.726: I/B4A(3002): ~e:   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
08-13 16:25:04.726: I/B4A(3002): ~e:   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
08-13 16:25:04.726: I/B4A(3002): ~e:   ... 11 more
 

ArminKH

Well-Known Member
Change theme from xml file to another one
The error message say this theme is not supported by app combat
 

fishwolf

Well-Known Member
Licensed User
Longtime User
Change theme from xml file to another one
The error message say this theme is not supported by app combat
now is set

B4X:
- <style name="MyAppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

what is a right theme for me?
 

ArminKH

Well-Known Member
now is set

B4X:
- <style name="MyAppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

what is a right theme for me?
You are using toolbar instead default actionbar so your app has not action bar(default action bar)
Change DarkActionBar to NoActionBar
 

corwin42

Expert
Licensed User
Longtime User
I have updated the Example in the attachment of the first post.

It fixes the "AppCompat does not support the current theme features" error. The problem is in the theme.xml file. All attributes MUST NOT have the android: prefix in their name. It is explained in the first post of the AppCompat library.
 

ArminKH

Well-Known Member
And what about my problem corwin?
My app language is write to left but the app combat does'n support write to left language
If the layout properties be accessable then i can reverse my view position
Or any suggestion?
 

corwin42

Expert
Licensed User
Longtime User
And what about my problem corwin?
My app language is write to left but the app combat does'n support write to left language
If the layout properties be accessable then i can reverse my view position
Or any suggestion?

Sorry, can you explain what you exactly want to do?
 

ArminKH

Well-Known Member
Sorry, can you explain what you exactly want to do?
yes
i am using AC Toolbar Which is a part of app compat library
we can put a navigation icon , logo icon , search view , menu , ... into this toolbar
this is good for english and all left to write language but if you read google developer documents about right to left language like persian or arabic
this languages are reverse of english
for example if navigation icon is in the left side of toolbar in english language then we should put it to right side
in other word all of views which is in left side must be in right side
please see attached scrren shot

in right to left languages the menu , search view , other extra actions must be in left side
and navigation icon , logo , title and sub title must be in right side of toolbar
https://www.google.com/design/spec/...ectionality-other-localization-considerations
 

Attachments

  • upload_2015-8-18_15-12-58.png
    105 bytes · Views: 343
Last edited:

corwin42

Expert
Licensed User
Longtime User

To support RTL languages try to set
B4X:
SetApplicationAttribute(android:supportsRtl, "true")
in the Manifest editor. This will reverse the item order in the ActionBar/Toolbar on RTL devices.
 

ArminKH

Well-Known Member
is this working on all android version?
and if our device language be english but our app's language be for example persian then this attribute works?
----------------------------
edit : @corwin42 when my device language is english then action bar is left to right but when my device language is persian then my actionbar is right to left
is there any way with no dependency on the phone language?
i want the phone's language be english but my actionbar be right to left
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…