当前位置: 动力学知识库 > 问答 > 编程问答 >

java - LibGdx newline TextArea in android

问题描述:

I created an android application with TextArea using LibGdx. My problem is whenever clicked in the touch screen keyboard's newline ("Enter" equivalent in keyboard), it doesn't return a newline. The text still written on the same line. However, it only moves on the second line if it fills the width of the textArea. How could I return a new line on the textarea widget?

网友答案:

Taken from this discussion: http://badlogicgames.com/forum/viewtopic.php?f=11&t=15112

Add the following to the show() function:

final StringBuilder build = new StringBuilder();
final TextArea textArea = new TextArea("", skin);
textArea.setTextFieldListener(new TextFieldListener()
{
    @Override
    public void keyTyped(TextField textField, char c)
    {
        // Handle a newline properly. If not handled here, the TextField
        // will advance to the next field.
        if (c == '\n')
        {
            textArea.setMessageText(build.append("\n").toString());
        }
    }
});

This solved the problem for me.

分享给朋友:
您可能感兴趣的文章:
随机阅读: