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
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 }
- oneI never thought that the textbutton will fully cope with my task, thanks - meow meow
|