问题
Is it possible to add an activity on top of the current activity. For example lets say i click a button, and then it adds a second activity to the current activity. And the second activity only covers a small place at the buttom of my current activity.
回答1:
The activity is just displaying a window, so you can use getWindow() to modify the window params to be what we want -- wrap content instead of fill parent for example. Though for an activity that is not going to be full screen, you should first do android:theme="@android:style/Theme.Dialog" in your manifest. That by itself will make the activity look like a dialog (dialog frame and wrap content centered on the screen). You can further refine the style or layout params from there.
That said, it is important to realize that the design is that there is only one activity running at a time. So when you show this new activity, your current one will be paused. (It won't be stopped because it is still visible behind your non-fullscreen activity.) For more integrated things, just have the base activity create a Dialog and adjust its window as desired in the same way. The decision about which to use is just a matter of which is more appropriate for your design, though I think a Dialog is a far more common approach here.
回答2:
The only way I know to have activities that don't take up the full screen is in a TabActivity and to make the activity a dialog. There could be others though. I'm not sure you can interact with both though.
回答3:
I found a perfect way. In manifest change the theme to Theme.Dialog, and call the activity with startActivityForResult, this way the root activity is still there, and the new activity will show up on top of it, and it has some nice transparency as well.
来源:https://stackoverflow.com/questions/3367869/android-sub-activity