Search code examples
nativescriptnativescript-angular

How can I get the tap sound when a user touch a gridlayout?


How can I get the tap sound when a user touch a gridlayout?

<GridLayout row="3" colSpan="2" columns="15*,75*,10*" height="12%" rows="*,*" class="card-large box" (tap)="onTap()">
    <Label text="&#xf17b;" class="fa centered icon-category" col="0" rowspan="2"></Label>
    <Label text="MyText" class="category-name" verticalAlignment="bottom" col="1" row="0"></Label>
    <Label text="numbers" verticalAlignment="top" col="1" row="1"></Label>
    <Label text="&#xf054;" class="fa centered icon-arrow" col="2" rowspan="2"></Label>
</GridLayout>

UPDATE: I could get the sound by accesing the android native api, here is the code:

let decorView:any = app.android.startActivity.getWindow().getDecorView() decorView.playSoundEffect(android.view.SoundEffectConstants.CLICK)

but I would like to know why tapping an android layout does not fire the sound effect,..


Solution

  • The above code should work as expected. Here is a demonstration application where the sound effect is triggered when the user taps on the layout (the layout with the tap event where the magic is happening)