0

Original Question: Just trying to find out if you can add an action bar through code in Nativescript JS And if so, How would you go about it?

New Question: So the following code loads the actionbar dynamically:

var actionB = require("tns-core-modules/ui/action-bar).ActionBar;

var actB = new actionB();
actB.title = "Action Bar";
actB.id = "actionID"

page.content = actB;

Now I just need to know how would I load navigation item and action item for android and ios

Thanks

4
  • I haven't tried that personally but should be same in the way your were adding grid and scroll view in stackoverflow.com/questions/52825771/… Commented Oct 18, 2018 at 4:45
  • Although I have created a shared component for action bar with different htms for android and ios and I use that on top of every other html Commented Oct 18, 2018 at 4:47
  • That would be perfect. Want I want to fully achieve is add and remove a navigation item, or load one actionbar, and then If I want a different one, load that one. Commented Oct 18, 2018 at 5:16
  • So got it working dynamically, just need to know how to load navigation items now Commented Oct 18, 2018 at 5:26

2 Answers 2

1

ActionBar is applicable for Page inside a Frame. Use actionBarHidden property of Page to show / hide ActionBar. Use actionItems property of ActionBar to add action items.

Sign up to request clarification or add additional context in comments.

3 Comments

I think Op's question was how to add actionbar dynamically using code not having that in html :)
Yeah, sorry for not being clear. Been going at this program for days. Just want to do something like. page.addChild(Actionbar);
No, it doesn't work that way. It's always part of a page and you may decide to hide or show it with that property. Set items / navigation button dynamically if you wany to.
1
var actionB = require("tns-core-modules/ui/action-bar).ActionBar;

var actB = new actionB();
actB.title = "Action Bar";
actB.id = "actionID"

var actionItemC = require("tns-core-modules/ui/action-bar).ActionItem;

var actItem = new actionItemC();
actB._addView(actItem)

and if you want to add navigation button

private getNavigationButton() {
    let navActionItem = new ActionItem();
    navActionItem.icon = 'res://ic_menu_white';
    if (navActionItem.ios) {
        navActionItem.ios.position = 'left';
    }
    navActionItem.on('tap', this.toggleDrawer.bind(this));
    return navActionItem;
}

and

if (isAndroid) {
        page.actionBar.navigationButton = this.getNavigationButton();
    }

    if (isIOS) {
        page.actionBar.actionItems.addItem(this.getNavigationButton());
    }

7 Comments

if you want to add NavigationButton than import it from same action bar module. require("tns-core-modules/ui/action-bar).NavigationButton
I'm trying to add a NavigationButton: var navB = new navButton(); navB.systemIcon = "ic_menu_btn_add": actionB._addView(navB); But I get nothing
When you debug can you see what is the icon asigned to navB?
when I console.log(navB.systemIcon); the Result is ic_menu_btn_add Is that what you mean?
that is great, do you want to try actionB.content = navB; Or may add all navigationitems to a grid or stacklayout then add.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.