Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nativescript add class to a button on Tap

Tags:

nativescript

I am completely new to Nativescript, I am trying to add class Name dynamically to a gridlayout on tap.

I am not using Angular 2.

How to access the grid layout element and add class name to the same.

like image 491
Madhu Avatar asked Nov 16 '16 20:11

Madhu


1 Answers

All that you need to do is search for the desired element in the UI tree for example by accessing the parent of the Button or by setting an id to the element and using the .getViewById() method of the root of the Page or the Page itself.

Finally in order to set the css class of that View simply set its className property, something like this:

export function onChangeCssClassButtonTap(args) {
    var button = args.object as Button;
    var parentGridLayout = button.parent as StackLayout;
    parentGridLayout.className = "myGridCssClassName";
}

Here are some documentation articles that may be useful to you:

  • Finding View by its id
  • Styling in NativeScript
like image 84
Vladimir Amiorkov Avatar answered Oct 03 '22 17:10

Vladimir Amiorkov