Reputation: 2869
My app contains only one activity and I want it to be opened as a small sized activity on top of the current active activity.
For example, if the app has a shortcut on the desktop and the user activates it then the main activity will open on top of the main desktop view in a small size (deviceHight / 2, deviceWidth / 2) box. If the app clicked from the app drawer the the drawer view will be visible behind the app activity.
Kind of a popup but with no parent activity.
Upvotes: 0
Views: 938
Reputation: 1622
Set your activity's theme as Dialog in AndroidManifest.xml
<activity android:theme="@android:style/Theme.Dialog">
Upvotes: 0
Reputation: 1576
Do you mean like a Dialog? Apply a custom theme to your activity will do the trick. Android have already defined a style which will make our Activity looks like a Dialog: @android:style/Theme.Dialog
.
There are two ways to apply theme to your activity:
android:theme
attribute to the activity in AndroidManifest.xmlThis is the easiest way to apply custom theme, following is an example:
<activity android:theme="@android:style/Theme.Dialog"
android:name=".MyActivity"/>
Activity.setTheme
methodYou should pass a style resource id to this method, in your case, you can use android.R.style.Theme_Dialog
. Note that you should call this method before you call setContentView
so that the theme will be applied to the content view.
public void onCreate(Bundle savedState) {
super.onCreate(savedState);
setTheme(android.R.style.Theme_Dialog);
setContentView(R.layout.main);
}
Upvotes: 2