自定義style,設置全屏屬性
<resources>
<style name="AppTheme" parent="Android:Theme.Black"/>
<style name="processDialog" >
<item name="android:windowIsFloating">true</item><!--是否浮現在activity之上-->
<item name="android:windowFullscreen">true</item>
<item name="android:windowIsTranslucent">false</item><!--半透明-->
<item name="android:windowNoTitle">true</item><!--無標題-->
<item name="android:windowBackground">@android:color/transparent</item><!--背景透明-->
<item name="android:backgroundDimEnabled">true</item><!--模糊-->
<item name="android:backgroundDimAmount">0.5</item>
<item name="android:alpha">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();
}
}
更多Android相關信息見Android 專題頁面 http://www.linuxidc.com/topicnews.aspx?tid=11