Android Tutorial Material Design 3 - Using a ToolBar as ActionBar

Anser

Well-Known Member
Licensed User
Longtime User

Anser

Well-Known Member
Licensed User
Longtime User
Dear joneden,

I am able to use the MsIconicDrawable for the NavigationIconDrawable ie the first one code provided by you , but unable to make use of MsIconicDrwable on the second code ie using AcMenuItem, could not understand what type of object is "Menu" in your code "Menu.Add2((1, 1, "Sync", icon.Drawable).ShowAsAction = item.SHOW_AS_ACTION_ALWAYS"

As of now I am using the code provided by corwin ie
B4X:
    Dim xml As XmlLayoutBuilder
    Dim bd As BitmapDrawable
    bd = xml.GetDrawable("ic_refresh_black_24dp")
    Activity.AddMenuItem3("Refresh", "MenuRefresh", bd.Bitmap, True)

I am unable to replace bd.Bitmap with bd.drawable, it will throw error.


How to use MSIconicDrawable to show the refresh button (Black color) on the ActionBar ? The black one displayed on the picture is a BitmapDrawable.


Would you mind helping me.

Regards
Anser
 

Cnrez

Member
Licensed User
Longtime User
hi again,

i want to change the color of text on actionbar
TitleTextColor and SubTitleTextColor
with these values :
#212121 and #727272

how do i write the syntax ?

ActionBar.SetAsActionBar
ActionBar.TitleTextColor ?
ActionBar.SubTitleTextColor ?


thanks

<color name="primary_text">#212121</color>
<color name="secondary_text">#727272</color>
 

Anser

Well-Known Member
Licensed User
Longtime User
i want to change the color of text on actionbar
TitleTextColor and SubTitleTextColor
with these values :
#212121 and #727272

I am also looking for a solution to change the Color of the Title/SubTitle text.

Right now, I understand that you need to decide upon a Parent theme either DARK or LIGHT
If you choose Theme DARK, then you will have the Texts on Title/SubTitle in White Color, if you choose LIGHT theme then the TitleText/SubTitle Text will be displayed in Black color.

May be the experts here will give you a solution, I just shared the information that I know.

I am yet to get a reply regarding using Drawable Icons using MSIconicDrawable on the ActionBar. It will avoid lot of unnecessary troubles in handing different images with different colors and resolutions.

Regards

Anser
 
Last edited:

ArminKH

Well-Known Member
@corwin42
hi is there any way to change the position of some child of toolbar?
for example i want to set Left property for title or i want to set left property for Navigation icon
i know all of them are adjusted by material design standard values but for some reason i need to change the layout of views programically after compile
for example i need to set the Left and Top and Height and Width of title bar and,etc... after compile with an animation
is there any way? maybe in java?
when i want to get views left property the log window show the message which is "Layout is not available"
thank u
 

corwin42

Expert
Licensed User
Longtime User
@corwin42
hi is there any way to change the position of some child of toolbar?
for example i want to set Left property for title or i want to set left property for Navigation icon

No, this is not supported. Be aware that the Toolbar is a standard Android component which is built by xml layout files which don't use the absolutelayout like B4A uses it for its designer created layouts. So there is no left and top, width and height property which could be used. If you need such custom layouts maybe you can use a simple transparent panel and put it on top of the Toolbar.
 

ArminKH

Well-Known Member
ok thank u
i can create my own toolbar but it seems other wrapper classes are just works with app combat toolbar
for example how to use ACMenu wrapper with my own toolbar which is created by panels,labels,etc... same to ACSearchView wrapper class?
 

corwin42

Expert
Licensed User
Longtime User
ok thank u
i can create my own toolbar but it seems other wrapper classes are just works with app combat toolbar
for example how to use ACMenu wrapper with my own toolbar which is created by panels,labels,etc... same to ACSearchView wrapper class?

This is not supported, then.
 

corwin42

Expert
Licensed User
Longtime User
(note that B4A is not based on AbsoluteLayout)
Yes, sorry. You are of course correct but it is very similar at least both have top, left, width and height properties so objects could be positioned with absolute coordinates. The internal Toolbar layout do not use layouts with absolute positioning.
 

paragkini

Member
Licensed User
Longtime User
Hi,
I have tried doing this project but while following tutorial 3, (it worked for tutorial 1 and 2) I am not able to compile the code.
Keep getting different errors. Also updated Android tools through SDK manager. Now I have stopped on below error.

B4X:
B4A version: 5.80
Parsing code.    (0.00s)
Compiling code.    (0.59s)
Compiling layouts code.    (0.01s)
Generating R file.    (7.78s)
Compiling generated Java code.    Error
javac 1.7.0_45
src\b4a\example\main.java:17: error: cannot find symbol
public class main extends android.support.v7.app.AppCompatActivity implements B4AActivity{
                                                ^
  symbol:   class AppCompatActivity
  location: package android.support.v7.app
Note: src\b4a\example\starter.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error

screenshot of settings.


SDK settings.
 

paragkini

Member
Licensed User
Longtime User
thanks corwin42, after a few searches have managed to put the correct file in additional libraries folder and it compiled without error.
However compiled app now doesn't run and gives "app has stopped error" upon execution. Guess need to do some more cleanup. Will check and come back if help needed...


[Update] there was a problem with android-support-v4 file. after replacing it, it started working. Thanks for your help.
 
Last edited:

Cnrez

Member
Licensed User
Longtime User
hi, solved

add this in your themes.xml file


<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyAppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#2196F3</item>
<item name="colorPrimaryDark">#1976D2</item>
<item name="colorAccent">#00BCD4</item>
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:textColorPrimary">#color whatever you want</item>
<item name="android:textColorSecondary">#color whatever you want</item>

</style>
</resources>


 

rudystyle

Member
Licensed User
Longtime User
Firstly thanks for the libraries and the amount of work that you have given away for free.
I made a small token donation of €10.00 to your paypal.
_______________________________________________________
I tried out a simple example and everything works fine.
However when I use the MsgBox function. The app crashes and in the debug window there is the error
java.lang.NoSuchMethodError: android.support.v4.view.ViewCompat.hasOnClickListeners
at android.support.v7.app.AppCompatViewInflater.checkOnClickListener(AppCompatViewInflater.java:196)
.
.
.


B4X:
Region  Project Attributes

#AdditionalRes: ..\resource  

#AdditionalRes: $AdditionalLibs$\resource\b4a_appcompat, de.amberhome.objects.appcompat
#AdditionalRes: $AndroidSDK$\extras\android\support\v7\appcompat\res, android.support.v7.appcompat

#Extends : android.support.v7.app.ActionBarActivity

    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False

#End Region

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 pContent As Panel
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("Main")
   
    '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 = "AppCompat"
ActionBar.SubTitle = "ToolBar Example 1"


Dim xml As XmlLayoutBuilder
Dim bd As BitmapDrawable
bd = xml.GetDrawable("ic_plus_one_black_24dp")
Activity.AddMenuItem3("Plus one", "Menu", bd.Bitmap, True)
bd = xml.GetDrawable("ic_refresh_black_24dp")
Activity.AddMenuItem3("Refresh", "Menu", bd.Bitmap, True)

End Sub

Sub Menu_Click
    Log("Clicked")
    Msgbox("sss","")
   
     
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
 

corwin42

Expert
Licensed User
Longtime User

NoSuchMethodErrors in one of the support libraries normally show that you have an outdated version of the support library installed in your B4A CustomLibs folders.

If the error is really related to the MsgBox call can you please post the full stacktrace?
 

JNG

Member
Licensed User
How to hide and show Toolbar when list is scrolling. Pl. suggest

regards
jng
 

divinglog

Member
Licensed User
Longtime User
Hi

When I select text in a TextView, the text selection toolbar does not overlay the app toolbar. Instead both toolbars are stacked, which looks really odd. Is there a way to prevent this? Is there an event for the text selection toolbar showing, so I can hide the app toolbar?

 

corwin42

Expert
Licensed User
Longtime User
How to hide and show Toolbar when list is scrolling. Pl. suggest

Unfortunately there is no simple way to do this. The ListView and ScrollView objects do not have the necessary events to handle this. If you use UltimateListView you can listen to events like scrollstatechange to hide or show the Toolbar.


Please try to add this to your theme:
B4X:
<item name="windowActionModeOverlay">true</item>
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…