2014-12-04 54 views
3

我正在用libgdx开发一个小游戏,并在我的屏幕上我想要一个标签(包裹在一个表格中),其中会有一个可点击的文本链接(带下划线或与不同的颜色)是这样的: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

回答

0

您可以通过使用两种不同的scene2d标签为“你可以查看代码”和“这里”,并设置点击收听到第二个做到这一点。你可以简单地改变“这里”标签的颜色和位置是根据第一标签位置就像使用以下pseduo代码:

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

如果您只需要标签可点击的一部分,我认为最好的方式来实现这是一种有两个标签,这应该工作:

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); 
+0

谢谢您的回答,但我已经尝试过这一点,如果添加两个标签宽度超过了表格的宽度,这是这里的情况下,它不能正常工作。此外,标签必须进行包装,以便可以在多行上显示,因为我有很长的句子要写,而不仅仅是“你可以在这里查看代码”。除了即使标签足够短,当我将它们添加到水平组时,它们也是彼此重叠(叠加)(抱歉我的英文不好)。我不知道该怎么办? – 2014-12-05 12:16:29