2017-04-13 80 views
1

我试着去定制的宽度和高度分配给我的自定义对话框 , 使用在平板电脑上的作品的代码IM棒棒糖及以上 但留下白斑运行Android奇巧我的手机上的对话框顶部。对话框定制宽度高度问题

enter image description here

代码片断

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

布局

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

回答

0

解决方案1:前的setContentView

dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 

()。

解决方案2: 添加自定义风格

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

然后加入这一行清单档案中的

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

谢谢

2

您应该添加requestFeature(Window.FEATURE_NO_TITLE)的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

白色区域是标题,你可以用这种方式隐藏标题。

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