LIBGDX:添加可点击的文本链接

时间:2014-12-04 12:29:56

标签: android hyperlink libgdx label

我正在用libgdx开发一个小游戏,在我的屏幕上我希望有一个标签(包裹在一个表格中),其中有一个可点击的文本链接(带下划线或颜色不同),如这样:

您可以在此处查看代码

here

编辑:

我尝试过的是:

HorizontalGroup monGroup = new HorizontalGroup();
Label howRotationRep = new Label("They have been based on the information provided on this ", new Label.LabelStyle(game.petiteFont, Color.WHITE));
howRotationRep.setWrap(true);
howRotationRep.setWidth(tailleCell);

Label test = new Label(" site", new Label.LabelStyle(game.petiteFont, Color.RED));
test.addListener(new ClickListener(){
@Override
public void clicked(InputEvent event, float x, float y) {

   Gdx.net.openURI("http://tetrisconcept.net/wiki/SRS");

}
});
monGroup.addActor(howRotationRep);
monGroup.addActor(test);
table.add(monGroup).left().width(tailleCell);

它给了我这个

this

2 个答案:

答案 0 :(得分:6)

如果您只需要部分Label可点击,我认为实现此功能的最佳方法是使用两个标签,这应该可行:

    Label lblReviewCode = new Label("You can review the code ", skin);
    Label lblReviewCodeLink = new Label("here", skin, "linkstyle");
    // If you don't want to provide a custom style...
    //Label lblReviewCodeLink = new Label("here", skin);
    lblReviewCodeLink.addListener(new ClickListener(){
        @Override
        public void clicked(InputEvent event, float x, float y) {
            Gdx.net.openURI("https://bitbucket.org/batman3000/batris");
        }
    });
    // If you didn't provided the style, you can at least paint it blue by doing this...
    //lblReviewCodeLink.setColor(Color.BLUE);

    HorizontalGroup codeLink = new HorizontalGroup();
    codeLink.addActor(lblReviewCode);
    codeLink.addActor(lblReviewCodeLink);

    table.add(codeLink);

答案 1 :(得分:0)

您可以使用两个不同的scene2d标签作为"您可以查看代码"和"在这里"并将click监听器设置为第二个。你可以简单地改变" here"的颜色。根据第一个标签位置标记和定位它,如使用以下pseduo代码:

label2.x = label1.x + label1.getTextWidth();
label2.y = label1.y;