I would like to change the back/home button icon in Titanium. I am able to do this using the Theme.
However I would like to change the icon at runtime after I apply the theme. The actionbar in titanium does not have any property or method to change the icon. Documentation. So I am using the hyperloop (native code) to change the icon, but unfortunately I am not able to access the actionbar.
Here is my view
<Alloy>
<Window class="container">
<ActionBar id="actionbar" displayHomeAsUp="true" homeButtonEnabled="true"></ActionBar>
<Label id="label" onClick="doClick">Hello, World</Label>
</Window>
</Alloy>
My code
import AppCompatActivity from 'android.support.v7.app.AppCompatActivity';
const activity = new AppCompatActivity(Ti.Android.currentActivity);
activity.getActionBar().setHomeAsUpIndicator(Titanium.Android.R.drawable.notificacion);
And the error
[ERROR] TiExceptionHandler: (main) [1,434] /alloy/controllers/index.js:69
[ERROR] TiExceptionHandler: activity.getActionBar().setHomeAsUpIndicator(Titanium.Android.R.drawable.notificacionmas);
[ERROR] TiExceptionHandler: ^
[ERROR] TiExceptionHandler: TypeError: activity.getActionBar(...).setHomeAsUpIndicator is not a function
[ERROR] TiExceptionHandler: at new Controller (/alloy/controllers/index.js:69:27)
[ERROR] TiExceptionHandler: at Object.exports.createController (/alloy.js:428:10)
[ERROR] TiExceptionHandler: at /app.js:22:7
[ERROR] TiExceptionHandler: at Module._runScript (ti:/module.js:608:9)
[ERROR] TiExceptionHandler: at Module.load (ti:/module.js:107:7)
[ERROR] TiExceptionHandler: at Module.loadJavascriptText (ti:/module.js:453:9)
[ERROR] TiExceptionHandler: at Module.loadAsFile (ti:/module.js:508:15)
[ERROR] TiExceptionHandler: at Module.loadAsFileOrDirectory (ti:/module.js:425:20)
[ERROR] TiExceptionHandler: at Module.require (ti:/module.js:255:17)
[ERROR] TiExceptionHandler: at Module.global.Module.require (/ti.main.js:11435:34)
[ERROR] TiExceptionHandler:
[ERROR] TiExceptionHandler: org.appcelerator.kroll.runtime.v8.V8Runtime.nativeRunModule(Native Method)
[ERROR] TiExceptionHandler: org.appcelerator.kroll.runtime.v8.V8Runtime.doRunModule(V8Runtime.java:162)
[ERROR] TiExceptionHandler: org.appcelerator.kroll.KrollRuntime.runModule(KrollRuntime.java:207)
[ERROR] TiExceptionHandler: org.appcelerator.titanium.TiLaunchActivity.loadScript(TiLaunchActivity.java:99)
[ERROR] TiExceptionHandler: org.appcelerator.titanium.TiRootActivity.loadScript(TiRootActivity.java:480)
[ERROR] TiExceptionHandler: org.appcelerator.titanium.TiLaunchActivity.onResume(TiLaunchActivity.java:183)
[ERROR] TiExceptionHandler: org.appcelerator.titanium.TiRootActivity.onResume(TiRootActivity.java:499)
[ERROR] TiExceptionHandler: android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1446)
[ERROR] TiExceptionHandler: android.app.Activity.performResume(Activity.java:7939)
[ERROR] TiExceptionHandler: android.app.ActivityThread.performResumeActivity(ActivityThread.java:4195)
[ERROR] V8Exception: Exception occurred at /alloy/controllers/index.js:69: Uncaught TypeError: activity.getActionBar(...).setHomeAsUpIndicator is not a function
Note
I believe this question is not a duplicate, since it is related to Titanium and not native Android.
I've updated my Hyperloop example at https://github.com/m1ga/hyperloop.collapsingToolbarLayout
It's using a custom back icon in the "collapsing toolbar" example screen. I've added a icon xml:
and assigning it with
(https://github.com/m1ga/hyperloop.collapsingToolbarLayout/blob/master/app/controllers/second.js#L44)
The full example is inside the repo