没有活动就无法触发对话框。
因此,您可以创建一个带有对话框主题的活动。
<activity android:theme="@android:style/Theme.Dialog" />
现在从您的服务..只需在您的通知到达时调用此活动...它会像对话框一样弹出...
Edit:
调用您的活动时:
startActivity(intent);
overridePendingTransition(R.anim.enter_anim, R.anim.right_exit_anim);
现在,在资源目录中名为 anim 的单独文件夹中创建两个动画文件。
输入动画:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_decelerate_interpolator">
<translate
android:fromYDelta="20%p" //this takes val from 0(screenbottom) to 100(screentop).
android:toYDelta="0%p" //this takes val from 0(screenbottom) to 100(screentop).
android:duration="700" //transition timing
/>
</set>
退出动画:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_decelerate_interpolator">
<translate
android:fromYDelta="0%p" //this takes val from 0(screenbottom) to 100(screentop).
android:toYDelta="20%p" //this takes val from 0(screenbottom) to 100(screentop).
android:duration="700" //transition timing
/>
</set>
EDIT 2:
创建一个活动..设计它..然后转到您的清单文件..并在您的活动标签下..添加:
<activity android:theme="@android:style/Theme.Dialog" />
现在您的活动将看起来像一个对话框......
EDIT 3:
现在在您的活动(对话框)中的 onCreate() 之后添加以下函数:
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
View view = getWindow().getDecorView();
WindowManager.LayoutParams lp = (WindowManager.LayoutParams) view.getLayoutParams();
lp.gravity = Gravity.RIGHT | Gravity.BOTTOM;//setting the gravity just like any view
lp.x = 10;
lp.y = 10;
lp.width = 200;
lp.height = 100;
getWindowManager().updateViewLayout(view, lp);
}
我们将覆盖附加窗口以指定屏幕上的活动位置。
现在您的活动将被放置在屏幕的右侧底部。
EDIT 4:
现在要为对话框指定指定的坐标点,请使用 lp.x 和 lp.y...