在我的Android应用中,我在custom dialog
中使用activity
。我已经为透明背景的自定义对话框指定了样式。我在Kitkat 4.4上遇到了奇怪的问题。对话框仅在Kitkat 4.4
上从顶部切出.SDK级别this链接,但没有获得如何实现我的要求的方法。
谢谢。
码:
public void showGameOverDialog(int score) {
final Dialog dialog = new Dialog(Level1Activity_Room.this,
R.style.DialogBackground);
dialog.setContentView(R.layout.gameover_dialog_layout);
dialog.setCanceledOnTouchOutside(false);
dialog.setCancelable(false);
dialog.show();
}
R.style.DialogBackground:
<style name="DialogBackground" parent="@android:style/Theme.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
</style>
最佳答案
最后,我通过对现有代码进行一些修改来解决了这个问题。还将目标级别从Android 4.4
更改为Project->Right Click->Android
public void showGameOverDialog(int score) {
final Dialog dialog = new customeDialogClass(Level1Activity_Room.this,
R.style.DialogBackground);
dialog.setContentView(R.layout.gameover_dialog_layout);
dialog.setCanceledOnTouchOutside(false);
dialog.setCancelable(false);
dialog.show();
}
customeDialogClass.java
@TargetApi(14)
public class customeDialogClass extends Dialog {
public customeDialogClass(Context context) {
super(context);
if (Build.VERSION.SDK_INT < 18) {
return;
}
// The UI options currently enabled are represented by a bitfield.
// getSystemUiVisibility() gives us that bitfield.
int uiOptions = getWindow().getDecorView().getSystemUiVisibility();
int newUiOptions = uiOptions;
boolean isImmersiveModeEnabled = ((uiOptions | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) == uiOptions);
if (isImmersiveModeEnabled) {
Log.e("log1---", "Turning immersive mode mode off.");
} else {
Log.e("log2-----", "Turning immersive mode mode on.");
}
// Status bar hiding: Backwards compatible to Jellybean
if (Build.VERSION.SDK_INT >= 16
&& (newUiOptions & View.SYSTEM_UI_FLAG_FULLSCREEN) <= 0) {
newUiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN;
}
if (Build.VERSION.SDK_INT >= 18
&& (newUiOptions & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) <= 0) {
newUiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
}
getWindow().getDecorView().setSystemUiVisibility(newUiOptions);
}
public customeDialogClass(Context context, boolean cancelable,
OnCancelListener cancelListener) {
super(context, cancelable, cancelListener);
}
public customeDialogClass(Context context, int theme) {
super(context, theme);
if (Build.VERSION.SDK_INT < 18) {
return;
}
// The UI options currently enabled are represented by a bitfield.
// getSystemUiVisibility() gives us that bitfield.
int uiOptions = getWindow().getDecorView().getSystemUiVisibility();
int newUiOptions = uiOptions;
boolean isImmersiveModeEnabled = ((uiOptions | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) == uiOptions);
if (isImmersiveModeEnabled) {
Log.e("log1---", "Turning immersive mode mode off.");
} else {
Log.e("log2-----", "Turning immersive mode mode on.");
}
// Status bar hiding: Backwards compatible to Jellybean
if (Build.VERSION.SDK_INT >= 16
&& (newUiOptions & View.SYSTEM_UI_FLAG_FULLSCREEN) <= 0) {
newUiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN;
}
if (Build.VERSION.SDK_INT >= 18
&& (newUiOptions & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) <= 0) {
newUiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
}
getWindow().getDecorView().setSystemUiVisibility(newUiOptions);
}
}