TextField - 在用户开始输入文本之前显示提示

发布于 2024-11-16 04:31:53 字数 110 浏览 1 评论 0原文

我正在开发一个黑莓应用程序。我想在用户开始输入之前在 TextField 中显示提示文本。当用户开始输入时,它应该消失,当 TextField 中有 0 个字符时,它应该显示。有人实现了这个吗?然后请分享。

I am developing an Blackberry application. I want to show a hint text in TextField before user starts typing.when user starts typing it should disappear and when there are 0 characters in TextField it should show up.Has anybody implemented this yet?then please share.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

逆光下的微笑 2024-11-23 04:31:53
protected void paint(Graphics g) 
{
    if(super.getText().length() == 0)
    {
        g.setColor(Color.GRAY);
        g.drawText("MMYY", 0, 0);
    }
    g.setColor(Color.BLACK);
    super.paint(g);
};
protected void paint(Graphics g) 
{
    if(super.getText().length() == 0)
    {
        g.setColor(Color.GRAY);
        g.drawText("MMYY", 0, 0);
    }
    g.setColor(Color.BLACK);
    super.paint(g);
};
我的鱼塘能养鲲 2024-11-23 04:31:53

这是我的尝试 - 这是一个完整的代码,您可以在 JDE 6.x 中运行它。

当您输入内容时,灰色字符串“Search”将消失:

screenshot

border.png:

border.png

src\mypackage\MyEdit.java:

package mypackage;

import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.decor.*;

public class MyEdit extends UiApplication {
    public static void main(String args[]) {
        MyEdit app = new MyEdit();
        app.enterEventDispatcher();
    }

    public MyEdit() {
        pushScreen(new MyScreen());
    }
} 

class MyScreen extends MainScreen {
    Border myBorder = BorderFactory.createBitmapBorder( 
        new XYEdges(20, 16, 27, 23), 
        Bitmap.getBitmapResource("border.png"));

    BasicEditField myField = new BasicEditField(TextField.NO_NEWLINE) {
        protected void paint(Graphics g) {
            if (getTextLength() == 0) {
                g.setColor(Color.LIGHTGRAY);
                g.drawText("Search", 0, 0);
            }

            g.setColor(Color.BLACK);
            super.paint(g);
        }
    };

    public MyScreen() {
        myField.setBorder(myBorder);
        setTitle(myField);
    }
}

Here is my try - it is a complete code, you can run it in JDE 6.x.

When you type something, the grey string "Search" will disappear:

screenshot

The border.png:

border.png

The src\mypackage\MyEdit.java:

package mypackage;

import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.decor.*;

public class MyEdit extends UiApplication {
    public static void main(String args[]) {
        MyEdit app = new MyEdit();
        app.enterEventDispatcher();
    }

    public MyEdit() {
        pushScreen(new MyScreen());
    }
} 

class MyScreen extends MainScreen {
    Border myBorder = BorderFactory.createBitmapBorder( 
        new XYEdges(20, 16, 27, 23), 
        Bitmap.getBitmapResource("border.png"));

    BasicEditField myField = new BasicEditField(TextField.NO_NEWLINE) {
        protected void paint(Graphics g) {
            if (getTextLength() == 0) {
                g.setColor(Color.LIGHTGRAY);
                g.drawText("Search", 0, 0);
            }

            g.setColor(Color.BLACK);
            super.paint(g);
        }
    };

    public MyScreen() {
        myField.setBorder(myBorder);
        setTitle(myField);
    }
}
无妨# 2024-11-23 04:31:53

这是 Paint() 方法中的实现

String test = super.getText();
        if ( test == null || test.length() < 1 ) {
            graphics.setColor( 0x00a0a0a0 );
            graphics.drawText(hint, 0, 0);
        }

,这是来源,感谢 peter_strange
http://supportforums.blackberry.com/t5/Java-Development/Prompt-hint-place-holder-text-on-a-Numeric-Password-edit-field/mp/990817#M151704< /a>

here is the implementation within paint() method

String test = super.getText();
        if ( test == null || test.length() < 1 ) {
            graphics.setColor( 0x00a0a0a0 );
            graphics.drawText(hint, 0, 0);
        }

and here is the source thanks to peter_strange
http://supportforums.blackberry.com/t5/Java-Development/Prompt-hint-place-holder-text-on-a-Numeric-Password-edit-field/m-p/990817#M151704

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文