简体   繁体   English

在Android中如何实现带有按钮的弹出屏幕。 单击按钮可调用活动中的不同功能

[英]In Android how to implement a pop-up screen with buttons. Clicking the buttons calls different functions in the activity

I am developing a game in Android. 我正在用Android开发游戏。 The game is implemented in the MainActivity.java and uses Relative Layout in xml. 该游戏在MainActivity.java中实现,并在xml中使用相对布局。 I want to implement a pause button, which when clicked opens a pop-up window with buttons for options like "1 player","2 Player","Change skin",'Challenge Friend" etc. 我想实现一个暂停按钮,单击该按钮会打开一个弹出窗口,其中包含诸如“ 1个玩家”,“ 2个玩家”,“更改皮肤”,“挑战好友”等选项的按钮。

1.How to create a layout at runtime with the buttons and can we destroy the layout when an option is clicked. 1.如何在运行时使用按钮创建布局,单击选项后我们是否可以销毁布局?

2.Can we get the id of the option button clicked in the dynamically created layout, to the MainActivity, so that the corresponding function can be called. 2.我们能否将在动态创建的布局中单击的选项按钮的ID转到MainActivity,以便可以调用相应的函数。

3.when dynamically creating the layout, will the values of the already existing layout be reset? 3.动态创建布局时,是否会重置现有布局的值?

4.Is dynamically creating layout and destroying it very expensive? 4.动态创建布局并销毁它是否非常昂贵?

I am new to android and so would really appreciate some help...Thankyou!!! 我是android新手,因此非常感谢您的帮助...谢谢!!!

Sounds like you just need an alert dialog with three buttons? 听起来您只需要一个带有三个按钮的警报对话框? Use the onlick functions in this answer . 此答案中使用onlick函数。 If you need an image view in the pop up see this answer and use similar tactics. 如果需要在弹出窗口中查看图像,请查看此答案并使用类似的策略。

如果要使用自定义布局的自定义对话框,请使用DialogFragment: http : //developer.android.com/reference/android/app/DialogFragment.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM