B4A Library MSMaterialMenu - Animating icons

thedesolatesoul

Expert
Licensed User
Longtime User
If you are lucky this might work:
B4X:
Dim bmd as BitmapDrawable = MyIconicDrawable.Drawable
Activity.AddMenuItem3(...bmd.Bitmap...)
 

Haris Hafeez

Active Member
Licensed User
Longtime User
If you are lucky this might work:
B4X:
Dim bmd as BitmapDrawable = MyIconicDrawable.Drawable
Activity.AddMenuItem3(...bmd.Bitmap...)
Thanks tds. But I have already tried it as well as tried using mutable bitmap to draw to a canvas. But they dont work
 

Haris Hafeez

Active Member
Licensed User
Longtime User
I get the following:


generalhelper_getbitmapfordrawable (java line: 31)
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.graphics.Canvas.drawPath(android.graphics.Path, android.graphics.Paint)' on a null object reference
at com.mikepenz.iconics.IconicsDrawable.draw(IconicsDrawable.java:497)
at anywheresoftware.b4a.objects.drawable.CanvasWrapper.DrawDrawable(CanvasWrapper.java:401)
at com.maximussoft.appcompatdrawer.generalhelper._getbitmapfordrawable(generalhelper.java:31)
at com.maximussoft.appcompatdrawer.main._activity_create(main.java:347)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
at com.maximussoft.appcompatdrawer.main.afterFirstLayout(main.java:100)
at com.maximussoft.appcompatdrawer.main.access$100(main.java:17)
at com.maximussoft.appcompatdrawer.main$WaitForLayout.run(main.java:78)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.graphics.Canvas.drawPath(android.graphics.Path, android.graphics.Paint)' on a null object reference

The helper code is:
B4X:
Public Sub GetBitmapForDrawable(pDrawable As MSIconicDrawable) As Bitmap
    Dim b As Bitmap
    b.InitializeMutable(24dip,24dip)
    Dim c As Canvas
    Dim r As Rect
    r.Initialize(0,0,24dip,24dip)
    c.DrawDrawable(pDrawable.Drawable, r)
    Return c.Bitmap
End Sub
 

Haris Hafeez

Active Member
Licensed User
Longtime User
Also give this a shot:
B4X:
Dim jo as JavaObject = MyIconicDrawable.Drawable
Dim bmp as Bitmap = jo.RunMethod("toBitmap",null)
Thank you. This is the one that works. As for the canvas object, I wasn't sure whether to initialize it or not as it takes a View as param. In my case, I just wanted to write to a rect. Perhaps I need to read up a bit on Canvas

Cheers.
 

thedesolatesoul

Expert
Licensed User
Longtime User
Thank you. This is the one that works. As for the canvas object, I wasn't sure whether to initialize it or not as it takes a View as param. In my case, I just wanted to write to a rect. Perhaps I need to read up a bit on Canvas

Cheers.
Yes you would need a view to draw on quickly, doevents, then hide it. Not ideal.
 

ArminKH

Well-Known Member
CAN u please tell me how i can use ARROW, CHECK state ?
OOOOOOOPS Solved
just try it with Legacy Debuger and not Rapid Debuger
 
Last edited:

ArminKH

Well-Known Member
@ thedesolatesoul
are u sure the icons are 24*24 ? when i use a 24*24 icon for my imageview the icon is in center and the dimensions is equel to other 24*24 icons
but when i want to load the drawabe of your lib like BURGER OR ARROW then the drawable is not in center and is a bit larger than 24*24
can u please check this? or replace the icons with material standard icons?please
 

dragonguy

Active Member
Licensed User
Longtime User
How do make it work on lollipop device, my app only work perfect on below lollipop version.
 
Last edited:

jarda

Member
Licensed User
Longtime User
MSMaterialMenu
do not work on Android 5.1.1

I can't actually open the menu, I try pressing the nav drawer icon and nothing appears to happen on my OPO
 
Last edited:

shashkiranr

Active Member
Licensed User
Longtime User
Hi @thedesolatesoul ,

I want to change the icon from up arrow to cross. I am not able to set the icon initially to arrow. It always comes as a BURGER. Is there a way I can set it to arrow ?

Best,
SK
 

Valounours

Member
Licensed User
Longtime User
Hello from France,

I have copy and paste your code to my projects but i have a error with this line :
"StdABHelper.Icon = MMenu.Drawable"

Any idea ?
 

Valounours

Member
Licensed User
Longtime User
Sorry, the log :

Installing file.
PackageAdded: package:com.maximussoft.materialdrawer
** Activity (main) Create, isFirst = true **
Error occurred on line: 106 (Main)
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.ActionBar.setIcon(android.graphics.drawable.Drawable)' on a null object reference
at de.amberhome.actionbarhelper.ActionBarHelper.setIcon(ActionBarHelper.java:99)
at com.maximussoft.materialdrawer.main._activity_create(main.java:635)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:702)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:246)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at com.maximussoft.materialdrawer.main.afterFirstLayout(main.java:102)
at com.maximussoft.materialdrawer.main.access$000(main.java:17)
at com.maximussoft.materialdrawer.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5461)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
** Activity (main) Resume **
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…