然后再看看CheckBox。CheckBox的样式定义在CheckBoxStyle中,需要4个参数,两种状态的各一张图片,一个BitmapFont和Color。

       这里我再添加一张图片:

Android游戏引擎libgdx使用教程5:常用UI类与舞台

       原理差不多,直接贴代码了。

Java代码
  1. package com.cnblogs.htynkn.listener;    

  2. import android.graphics.Paint.Align;    

  3. import com.badlogic.gdx.ApplicationListener;    

  4. import com.badlogic.gdx.Gdx;    

  5. import com.badlogic.gdx.graphics.Color;    

  6. import com.badlogic.gdx.graphics.GL10;    

  7. import com.badlogic.gdx.graphics.Texture;    

  8. import com.badlogic.gdx.graphics.g2d.BitmapFont;    

  9. import com.badlogic.gdx.graphics.g2d.NinePatch;    

  10. import com.badlogic.gdx.graphics.g2d.TextureRegion;    

  11. import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment;    

  12. import com.badlogic.gdx.scenes.scene2d.Actor;    

  13. import com.badlogic.gdx.scenes.scene2d.Stage;    

  14. import com.badlogic.gdx.scenes.scene2d.actors.Label;    

  15. import com.badlogic.gdx.scenes.scene2d.ui.Button;    

  16. import com.badlogic.gdx.scenes.scene2d.ui.CheckBox;    

  17. import com.badlogic.gdx.scenes.scene2d.ui.ClickListener;    

  18. import com.badlogic.gdx.scenes.scene2d.ui.Button.ButtonStyle;    

  19. import com.badlogic.gdx.scenes.scene2d.ui.CheckBox.CheckBoxStyle;    

  20. public class FirstGame implements ApplicationListener {    

  21. private Stage stage;    

  22. Label label;    

  23. Texture texture1;    

  24. Texture texture2;    

  25. CheckBox checkBox;    

  26. @Override    

  27. public void create() {    

  28. stage = new Stage(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(),    

  29. true);    

  30. texture1 = new Texture(Gdx.files.internal("06.png"));    

  31. texture2 = new Texture(Gdx.files.internal("07.png"));    

  32. NinePatch n1 =  android开发,青软培训