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.
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
精彩评论