1

Im trying to assign custom width and height to my custom dialog , the code im using works on tablets lolipop and above but leaves a white patch on top of the dialog on my phone running android kitkat .

enter image description here

Code snippet

Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.dialog_documentationissue_notification);
dialog.setCancelable(true);

DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int width = (int) (displaymetrics.widthPixels * 0.90);
int height = (int) (displaymetrics.heightPixels * 0.70);
dialog.getWindow().setLayout(width,height);
//dialog.getWindow().getAttributes().windowAnimations = R.style.NotificationDialogAnimation;
dialog.show();

Layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:background="@android:color/transparent"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.15"
        android:background="#3F51B5"
        android:orientation="vertical">

        <View
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.85"
        android:background="@color/white"
        android:orientation="vertical">

        <View
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </LinearLayout>

</LinearLayout>

3 Answers 3

3

You should add requestFeature(Window.FEATURE_NO_TITLE) before setContentView.

 dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); //Optional
 dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
 dialog.setContentView(R.layout.dialog_documentationissue_notification);
Sign up to request clarification or add additional context in comments.

Comments

0

Solution 1:

dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

before setContentView().

Solution 2: add custom style

<style name="myDialog" parent="android:style/Theme.Dialog">
   <item name="android:windowNoTitle">true</item>
</style>

then add this line in your manifest file

<activity android:name=".youractivity" android:theme="@style/myDialog"></activity>

Thank you,

Comments

0

That white area is for title,you can hide title this way.

 dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); //before     
 dialog.setContentView(R.layout.logindialog);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.