I have the following class
public class GameActivity extends Activity {
   @Override
   public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      View gameView = new GameView(this);
      setContentView(gameView);
   }
}
and now I'd like to add a Button to my class GameView.
public GameView(Context context) {
        super(context);
// Code ...
}
I need this button during my game, so it should be alywas in front of all the other canvas' I'm drawing.
 How can I do that?
Add Action Buttons To add actions to the action bar, create a new XML file in your project's res/menu/ directory. The app:showAsAction attribute specifies whether the action should be shown as a button on the app bar.
Do you want to create a new button?
Button b = new Button(context);
b.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, 
                                   LayoutParams.WRAP_CONTENT)); 
gameView.addView(b);
Use ViewGroup as GameView parent insted of simple View
ViewGroup gameView = new GameView(this);
public class GameView extends ViewGroup { //...
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With