开发者

Android popup on top of desktop view

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 deskto开发者_Python百科p 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.


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:

1, Set android:theme attribute to the activity in AndroidManifest.xml

This is the easiest way to apply custom theme, following is an example:

<activity android:theme="@android:style/Theme.Dialog"
    android:name=".MyActivity"/>

2, Using Activity.setTheme method

You 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);
}


Set your activity's theme as Dialog in AndroidManifest.xml

<activity android:theme="@android:style/Theme.Dialog">
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜