自定义style,设置全屏属性
<resources>
<style parent="Android:Theme.Black"/>
<style >
<item>true</item><!--是否浮现在activity之上-->
<item>true</item>
<item>false</item><!--半透明-->
<item>true</item><!--无标题-->
<item>@android:color/transparent</item><!--背景透明-->
<item>true</item><!--模糊-->
<item>0.5</item>
<item>0.3</item>
</style>
</resources>
代码中加载这个view并把view set到dialog上,这样全屏的dialog就完成了
mView = LayoutInflater.from(this).inflate(R.layout.process_dialog, null);
processDialog = new Dialog(LogActivity.this, R.style.processDialog);
processDialog.setCancelable(false);
processDialog.setContentView(mView);
mAutoCloseDialog = new AutoCloseDialog(processDialog);
mAutoCloseDialog.show(Prefs.DIALOG_DISPLAY_TIME);
接下来用一个封装好的类,做一个延时关闭的效果
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import android.app.Dialog;
public class AutoCloseDialog{
private Dialog dialog;
private ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
public AutoCloseDialog(Dialog dialog){
this.dialog = dialog;
}
public void show(long duration){
Runnable runner = new Runnable() {
public void run() {
dialog.dismiss();
}
};
executor.schedule(runner, duration, TimeUnit.MILLISECONDS);
dialog.show();
}
}