在我的Android应用中,我在custom dialog
中使用activity
。我为这个自定义对话框提供了透明背景的样式。我在Kitkat 4.4上遇到了奇怪的问题。该对话框仅在Kitkat 4.4
上从顶部剪切。具有sdk级别< 4.4根据我的要求给出适当的输出。为什么会这样?请求帮助我解决这个问题。我尝试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>
答案 0 :(得分:1)
最后,我通过对现有代码进行了一些修改来解决了这个问题。还将目标级别从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);
}
}
答案 1 :(得分:0)
问题不在kitkat 4.4中,我认为问题出现在R.layout.gameover_dialog_layout中以获得屏幕支持
答案 2 :(得分:0)
它通常会通过Android 4.4或更低版本中添加的标题栏。 通过将以下行添加到自定义对话框中来解决此问题。
* * * * * echo $(/usr/share/rvm/rubies/ruby-2.3.3/bin/ruby -v) >> 123.rb
* * * * * echo "123" >> 123.rb