Workaround for Android 4.4 Dialog blocked by status bar

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.