2017-04-13 1 views
1

Im essayant d'attribuer une largeur et une hauteur à mon dialogue personnalisée , le code im en utilisant les travaux sur les tablettes Lolipop et au-dessus mais laisse une tache blanche sur le dessus de la boîte de dialogue sur mon téléphone fonctionnant sous Android KitKat .Dialog problème de hauteur de largeur personnalisée

enter image description here

extrait de code

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(); 

Mise en page

<?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> 

Répondre

0

Solution 1:

dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 

avant setContentView().

Solution 2: ajouter du style personnalisé

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

puis ajoutez cette ligne dans votre fichier manifeste

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

Merci,

2

Vous devez ajouter requestFeature (Window.FEATURE_NO_TITLE) avant 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); 
0

Cette zone blanche est pour le titre, vous pouvez masquer le titre de cette façon.

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