Sencha Touch Label - does it have a Tap Event?

隐身守侯 提交于 2019-12-06 02:20:26

问题


I'm trying to build a flashcard app with sencha touch 2. I have a label showing the question, which takes up the entire screen, I want it so that when the user taps on the label the answer shows. Does the label have a 'tap' event? It works when I use a button, but not when I use a label.

Another way around is if I can get the button to be transparent on top of a label. Any suggestions?


回答1:


You can do this :

label.element.on({
    tap : function(e, t) { ... }
});

Hope this helps




回答2:


one more way to bind the tap event to the 'label' control using sencha touch.

{
    xtype : 'label',
    html : 'my name is abc',
    listeners : 
    {
        element : 'element',
        tap : function(e, t) 
         {
           alert('1 pressed');
         }
    }
}



回答3:


Ext.Label is not designed to have a tap event. However, you can still achieve it through the tap event on your label HTML element, for example:

label.getContentEl().on{'tap', handler_function,this}

But Sencha Touch does not provide tap event on Ext.Label, which is a child of Ext.Component, so when you try to use tap event on a label, it's not the best practice.

A better approach is to use Ext.Button with the following 2 configs:

{
  ui: 'plain',
  cls: 'btnCls',
}

and in your CSS, style its background to transparent.



来源:https://stackoverflow.com/questions/10688484/sencha-touch-label-does-it-have-a-tap-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!