gpt4 book ai didi

android - Titanium button.backgroundGradient focus

转载 作者:行者123 更新时间:2023-11-29 00:37:25 25 4
gpt4 key购买 nike

我正在开发 Titanium 移动应用程序,但在使用 backgroundRadient 时遇到按钮聚焦问题。

我使用 touchstart 事件取得了成功(changeBackgroundGradient 很简单,可以避免在此处显示):

authButton.addEventListener('touchstart', function(e) {
changeBackgroundGradient(authButton);
});

但是touchend事件不是我想要的。仅当用户结束触摸元素(表现为点击事件)时才会触发。Touchmove 也不是我想要的,因为它会在用户移动时立即触发。

authButton.addEventListener('touchmove', function(e) {
revertBackgroundGradient(authButton);
});

我想要的是:只要用户触摸按钮,按钮就处于焦点上。类似于“ontap”和“onrelease”之类的东西。我知道有 backgroundFocusedColor 和 backgroundFocusedImage,但没有 backgroundFocusedGradient。

如何在使用 backgroundGradient 属性时处理按钮焦点?我想要默认行为,但它似乎在我使用 backgroundGradient 属性后立即停止。

谢谢。

--编辑:

完整代码如下:

        // Authenticate Button
var authButton = Ti.UI.createButton({
width : '50%',
height : '60',
top : '15',
bottom : '15',
title : L('LoginView_authButton'),
font: {
fontSize: 20,
fontFamily: 'TrebuchetMS-Bold'
},
color : '#FFFFFF',
textAlign : 'center',
borderColor : '#3D86A9',
borderWidth : '2',
borderRadius : '5',
backgroundGradient : {
type : 'linear',
startPoint : {
x : '0%',
y : '0%'
},
endPoint : {
x : '0%',
y : '100%'
},
colors : [{
color : '#a2d6eb',
offset : 0.0
}, {
color : '#67afcf',
offset : 0.5
}, {
color : '#3591bc',
offset : 0.5
}, {
color : '#1e83b1',
offset : 1.0
},
]
}
});

authButton.addEventListener('touchstart', function(e) {
changeBackgroundGradient(authButton);
});

authButton.addEventListener('touchend', function(e) {
revertBackgroundGradient(authButton);
});

function changeBackgroundGradient(AuthButton)
{
AuthButton.backgroundGradient = {
type : 'linear',
startPoint : {
x : '0%',
y : '0%'
},
endPoint : {
x : '0%',
y : '100%'
},
colors : [{
color : '#f5bd8b',
offset : 0.0
}, {
color : '#e59a57',
offset : 0.5
}, {
color : '#da7a23',
offset : 0.5
}, {
color : '#c35211',
offset : 1.0
},
]
};
}

function revertBackgroundGradient(AuthButton)
{
AuthButton.backgroundGradient = {
type : 'linear',
startPoint : {
x : '0%',
y : '0%'
},
endPoint : {
x : '0%',
y : '100%'
},
colors : [{
color : '#9FD3E9',
offset : 0.0
}, {
color : '#63AAC9',
offset : 0.5
}, {
color : '#348BB8',
offset : 0.5
}, {
color : '#2081B2',
offset : 1.0
},
]
};
}

最佳答案

哦,好的,我现在明白了,它按预期工作,这不是错误,因为您将事件监听器添加到按钮,所以它只适用于按钮。

您可能想向 authButton 添加一个名为 isFocused 或类似名称的属性。在 touchstart 事件中,添加:

authButton.isFocused:true;

然后在包含具有还原功能的 authButton 的 View /窗口上添加 touchend 事件。

你知道为什么吗?

关于android - Titanium button.backgroundGradient focus,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11761795/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com