Android 4.4 Dialog is blocked by the status bar. androiddialog
First, check the abnormal figure. Click the tracing_dialog button to bring up the dialog box.
Then, in theory
Observe the two figures and find that the top of the abnormal figure is blocked by the status bar, and this problem exists in android4.4. To fix this problem, we add a function in the Dialog subclass to fix android4.4 and later versions, but not android4.4 or later versions.
Let's first look at the problematic code.
package cn.edu.zafu.demo;import android.app.Dialog;import android.content.Context;import android.os.Build;import android.os.Bundle;import android.view.WindowManager;/** * Created by lizhangqu on 2015/5/22. */public class TracingDialog extends Dialog { public TracingDialog(Context mContext, int style) { super(mContext, style); setCancelable(false); } protected void onCreate(Bundle paramBundle) { setContentView(R.layout.tracing_dialog); }}
The method for creating a Dialog is as follows. The first parameter is the Context object, and the second parameter is the id of the topic file.
TracingDialog dialog=new TracingDialog(MainActivity.this, R.style.kdialog);dialog.show();
The style is as follows:
<style name="kdialog" parent="@android:style/Theme.Dialog"> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowFrame">@null</item> <item name="android:windowNoTitle">true</item> <item name="android:windowIsFloating">true</item> <item name="android:windowIsTranslucent">false</item> <item name="android:backgroundDimEnabled">false</item></style>
Now we add a function in TracingDialog to adapt to android4.4 and later versions to make it display normally. The added function is as follows:
private void applyCompat() { if (Build.VERSION.SDK_INT < 19) { return; } getWindow().setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);}
Call the above function in the onCreate method of TracingDialog, as shown below:
protected void onCreate(Bundle paramBundle) { applyCompat(); setContentView(R.layout.tracing_dialog);}
If you do not want to inherit the Dialog method, you cannot create a Dialog. We recommend that you use DialogFragment to create Dialog. In this way, a function solves the problem!
References
- Dialog-on-android-kitkat-seems-to-be-cut