打开对话框主题为“浮动”的活动在当前活动之上
可能有更好的方法,如果是这样,请告诉我,因为我是 Android 开发的新手......
我有一个带有“主要”活动的应用程序。用户可以从此按钮打开另一个活动,在其中可以编辑应用程序的设置。我不想在新的“屏幕”上打开活动,而是想在主活动顶部打开一个类似弹出窗口(模式)的窗口,以保存设置活动。用户将能够看到设置弹出窗口后面的主屏幕,但在按下设置上的“保存”或“取消”之前无法与其交互。
我使用对话框主题进行了设置活动。当我按下按钮打开设置时,我会看到我想要的设置活动,除了主要活动消失并且我在后台看到我的主屏幕。然后,当我在设置活动上按下“保存”时,我的主要活动将返回全屏。
有没有简单的方法来纠正这个问题?我是否没有使用正确的方法来实现我想要做的事情?我已在主要活动中包含了用于设置按钮的 onclick 处理程序。
//Settings button
private OnClickListener oclSettingsButtonClick = new OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), settingsActivity.class);
startActivityForResult(myIntent, 0);
finish();
}
任何帮助表示赞赏。
There may be a better approach for this, and if so please let me know as I am new to android development...
I have an app with a "main" activity. From this the user can push a button to open another activity where they can edit settings for the app. Instead of opening the activity on a new 'screen' I would like to open a popup like window (modal) on top of the main activity that will hold the settings activity. The user will be able to see to main screen behind the settings popup but not interact with it until they push 'save' or 'cancel' on settings.
I made my settings activity with the dialog theme. When I push the button to open settings, I see the settings activity as I would like, except the main activity goes away and I see my home screen in the background. Then when I push save on settings activity, my main activity comes back full screen.
Is there an easy way to correct this? Am I not using to correct method to achieve what I am looking to do? I've included my onclick handler for the settings button on the main activity.
//Settings button
private OnClickListener oclSettingsButtonClick = new OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), settingsActivity.class);
startActivityForResult(myIntent, 0);
finish();
}
Any help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,设置处理得很好,如果您使用preferenceActivity,设置可能会更容易。这种开箱即用的方法不会给你带来你想要的东西,但它会大大减少你的编码量。
这是相关教程: http://www.kaloer.com/android-preferences
您也许可以在其上使用透明主题并获得您正在寻找的效果,但我还没有尝试过。
如果您确实想要一个弹出窗口覆盖您的主要活动,自定义对话框将相当轻松地帮助您实现目标。
http://developer.android.com/guide/topics/ui/dialogs .html#CustomDialog
http://www .helloandroid.com/tutorials/how-display-custom-dialog-your-android-application
First, settings are well handled and will probably be easier if you use a preferenceActivity. this out of the box will not get you what you want, but it will result in significantly less coding for you.
here is a tutorial on that: http://www.kaloer.com/android-preferences
you may be able to use a transparent theme on that and get achieve the effect you are looking for, I haven't tried though.
If you really want a popup overlaying your main activity, a custom dialog will get you there fairly easily.
http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog
http://www.helloandroid.com/tutorials/how-display-custom-dialog-your-android-application