【问题标题】:CodenameOne change button icon when pressedCodenameOne 按下时更改按钮图标
【发布时间】:2014-04-18 23:59:40
【问题描述】:

我将图像设置为按钮的图标。 按下图标时我需要更改图像。 我怎样才能在代号中实现这一点。 BR, 卫生巾

【问题讨论】:

    标签: codenameone


    【解决方案1】:

    你的意思是当按钮被按下的时候?就像,只要按住它并在释放时恢复原始图像?

    您可以通过创建自己的按钮来做到这一点,该按钮从 CodenameOne 的按钮扩展而来。在这个新按钮中,您可以覆盖“Pressed”和“Released”应该执行的操作。但请记住,释放按钮也有一个与之关联的动作,它会恢复“未按下”的样式。

    例如

     public class NewButton extends Button
     {
    
    public NewButton()
    {
               super();
    }
    
    @Override
    public void pressed()
    {    
        super.pressed(); // To change the state of the button to pressed
        try
        {
            Resources r = Resources.open("/theme.res");
            Image pressed = r.getImage("bomb.png"); // Just an image I had in a project. 
            this.getStyle().setBgImage(pressed);
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
    }
    

    【讨论】:

      【解决方案2】:

      按钮具有用于按下/翻转/选定版本图标的图像。

      【讨论】:

        猜你喜欢
        • 2023-02-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-06-06
        • 1970-01-01
        • 1970-01-01
        • 2017-12-28
        相关资源
        最近更新 更多