Android 4.4 Dialog is blocked by the status bar. androiddialog

Source: Internet
Author: User

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

Related Article

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.