First look at the abnormal diagram, click the Tracing_dialog button Pop-up dialog box
And look at the theory.
Observing two graphs, it is found that the top of the abnormal graph is obscured by the status bar, and the problem exists in the android4.4 version. To fix this problem, we added a function in the subclass of dialog, fixed for android4.4 and above, and android4.4 the following versions are not processed.
Let's take a look at the problematic code first.
PackageCn.edu.zafu.demo;ImportAndroid.app.Dialog;ImportAndroid.content.Context;ImportAndroid.os.Build;ImportAndroid.os.Bundle;ImportAndroid.view.WindowManager;/** * Created by Lizhangqu on 2015/5/22. * * Public class tracingdialog extends Dialog { Public Tracingdialog(Context Mcontext,intStyle) {Super(Mcontext, style); Setcancelable (false); }protected void onCreate(Bundle Parambundle) {Setcontentview (R.layout.tracing_dialog); }}
The method to create the dialog is as follows, the first parameter is the context object, the second argument is the ID of the subject file
TracingDialog dialog=new TracingDialog(MainActivity.this, R.style.kdialog);dialog.show();
Style as follows
<stylename="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 to the tracingdialog, which makes the android4.4 and the above version fit to show normal, the added function is as follows
private void applyCompat() { if (Build.VERSION.SDK19) { return; } getWindow().setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);}
Call the above function in the OnCreate method of Tracingdialog, as follows
protectedvoidonCreate(Bundle paramBundle) { applyCompat(); setContentView(R.layout.tracing_dialog);}
Let's not consider inheriting dialog this way of creating dialog, there is no way, the history left the problem. Dialog's creation method has been suggested to be created using Dialogfragment. In this way, a function solves the problem!
Reference articles
- Dialog-on-android-kitkat-seems-to-be-cut
Workaround for Android 4.4 Dialog blocked by status bar