How to create ImageTextButton, there is much less information on the Internet about this than about a simple ImageButton, does anyone have an example of creating this button with text?

  • Give an example in the form of a picture. - Andrey Mihalev
  • picture of what? code? - meow meow
  • You can also use an ordinary Button with text, add background, or drawableLeft, drawableRight, etc. and text - Alex Tremasov
  • A picture of what you want to do. From the description it is not at all clear what you want to achieve! - Andrey Mihalev

1 answer 1

If you want a button with a background and text, the usual TextButton will suit you. TextButtonStyle inherits the qualities of an ordinary button, namely, to have a background-image.

How to make without skins:

 // Π‘ΠΎΠ·Π΄Π°Π΅ΠΌ ΡΡ‚ΠΈΠ»ΡŒ для ΠΊΠ½ΠΎΠΏΠΊΠΈ TextButton.TextButtonStyle textButtonStyle = new TextButton.TextButtonStyle(); // ΠŸΠ΅Ρ€Π΅ΠΎΠΏΡ€Π΅Π΄Π΅Π»ΡΠ΅ΠΌ Π½ΡƒΠΆΠ½Ρ‹Π΅ ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€Ρ‹ (Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€, up - ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° ΠΎΠ±Ρ‹Ρ‡Π½ΠΎΠ³ΠΎ состояния ΠΊΠ½ΠΎΠΏΠΊΠΈ). // Π’Π°ΠΊ ΠΆΠ΅ Π½ΡƒΠΆΠ½ΠΎ Π·Π°Π΄Π°Ρ‚ΡŒ font, опустил для краткости. textButtonStyle.up = new TextureRegionDrawable(/*сюда ΠΏΠ΅Ρ€Π΅Π΄Π°Π΅ΠΌ TextureRegion*/); TextButton textButton = new TextButton("Π’ΡƒΡ‚ тСкст ΠΊΠ½ΠΎΠΏΠΊΠΈ", textButtonStyle); 

With skins:

 TextButton backButton = new TextButton("ВСкст ΠΊΠ½ΠΎΠΏΠΊΠΈ", Utility.UI_SKIN, "default-button-with-background"); 

In json skin:

  "com.badlogic.gdx.scenes.scene2d.ui.TextButton$TextButtonStyle": { ...ΠΏΡ€ΠΎΡ‡ΠΈΠ΅ стили TextButton "default-button-with-background": { "font": "default-font", //ΡˆΡ€ΠΈΡ„Ρ‚ "fontColor": "black", //Ρ†Π²Π΅Ρ‚ "up": "buttonRegular", //Π½Π°Π·Π²Π°Π½ΠΈΠ΅ тСкстуры ΠΎΠ±Ρ‹Ρ‡Π½ΠΎΠ³ΠΎ состояния ΠΊΠ½ΠΎΠΏΠΊΠΈ для Ρ„ΠΎΠ½Π° }, ...ΠΏΡ€ΠΎΡ‡ΠΈΠ΅ стили TextButton } 
  • one
    I never thought that the textbutton will fully cope with my task, thanks - meow meow