Nativescript-模拟在标签元素上按下按钮
我使用标签元素作为按钮。button元素有太多的填充,我似乎无法覆盖 在标签上,我想给出一个“按钮”按钮反馈,我在ontap事件回调期间做了以下操作 ` ` 但是延迟似乎比125毫秒长得多——更接近一秒 任何关于如何做得更好的建议。对于您最初的问题(按钮有太多的填充),听起来好像您正在尝试将样式应用于CSS中的按钮 相反,为按钮添加所需宽度和高度的XML属性:Nativescript-模拟在标签元素上按下按钮,nativescript,Nativescript,我使用标签元素作为按钮。button元素有太多的填充,我似乎无法覆盖 在标签上,我想给出一个“按钮”按钮反馈,我在ontap事件回调期间做了以下操作 ` ` 但是延迟似乎比125毫秒长得多——更接近一秒 任何关于如何做得更好的建议。对于您最初的问题(按钮有太多的填充),听起来好像您正在尝试将样式应用于CSS中的按钮 相反,为按钮添加所需宽度和高度的XML属性: <Button text="TAP" tap="{{ onTap }}" class="btn btn-primary btn-a
<Button text="TAP" tap="{{ onTap }}" class="btn btn-primary btn-active" width="150" height="25"/>
您可以发出指令,在任何对象上模拟聚焦/强光效果。 创建一个指令文件并将其添加到app.module 它会在事件“触地”和“触地”时更改,这是您所选元素的属性 指令1.ts
import { Directive, ElementRef, Input, OnInit } from '@angular/core';
import { GestureTypes, TouchAction } from 'tns-core-modules/ui/gestures';
@Directive({selector: '[focus]'})
export class FocusDirective implements OnInit {
private defaultColor: string;
private color = '#000000';
constructor(private elementRef: ElementRef) {
}
ngOnInit(): void {
const nativeElement = this.elementRef.nativeElement;
this.defaultColor = nativeElement.color;
// you can change here a lot of properties not only color
nativeElement.on(GestureTypes.touch, ({action}) => {
switch (action) {
case TouchAction.down: {
nativeElement.color = this.color;
break;
}
case TouchAction.up: {
setTimeout(() => {
nativeElement.color = this.defaultColor;
}, 80);
break;
}
default: {
nativeElement.color = this.defaultColor;
}
}
});
}
@Input() set focus(color: string) {
if (color) {
this.color = color;
}
}
}
template.html
<Label text="some text" focus="#FFF000"></Label>
<Label text="some text" focus="#FFF000"></Label>