<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
主程式加入
final AlertDialog.Builder mAB = new AlertDialog.Builder(this);
final DialogInterface.OnClickListener di_onclick = new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
switch(which)
{
case ID_SELECT: //int ID_SELECT = 0;
break;
case ID_DELETE: //int ID_DELETE = 1;
break;
}
}
};
mAB.setTitle(R.string.str_dialog_title);
mAB.setIcon(R.drawable.dialog_title_icon);
mAB.setItems(R.array.dialog_item, di_onclick);
AlertDialog alert = mAB.create();
alert.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
alert.show();
./res/values/arrays.xml
<resources>
<string-array name="dialog_item">
<item>Launch</item>
<item>Uninstall</item>
</string-array>
</resources>
<string-array name="dialog_item">
<item>Launch</item>
<item>Uninstall</item>
</string-array>
</resources>
若要關閉此對話框則下
alert.dismiss();
沒有留言:
張貼留言