2013-10-05 73 views
-1

我想创建一个自定义对话框,其中我想提示用户输入密码。为此我正在扩大Dialog Class.But我的对话框看起来像这样这不是我想要的 enter image description here自定义对话框布局

这里是我的代码和布局文件

<?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:background="@color/colorMenuBackground" 
    android:orientation="vertical" 
    android:padding="15dip" > 

    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:text="Login" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:textColor="#ffffff" /> 

    <TableRow 
     android:layout_width="fill_parent" 
     android:layout_height="2dip" 
     android:background="#ffffff" 
     android:layout_marginBottom="15dip"> 
    </TableRow> 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/register_form_textview_background" 
     android:padding="10dip" 
     android:text="Password" /> 

    <EditText 
     android:id="@+id/etmyPass" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="15dip" 
     android:background="@drawable/edittext" 
     android:ems="10" 
     android:inputType="textPassword" 
     android:padding="10dip" > 
    </EditText> 

    <Button 
     android:id="@+id/blogin" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/app_button" 
     android:text="Login" 
     android:textStyle="bold" /> 

</LinearLayout> 

customDialog.java

package com.example.mywebaccounts.Dialogs; 

import com.example.mywebaccounts.R; 

import android.app.Dialog; 
import android.content.Context; 
import android.os.Bundle; 

public class LoginDialog extends Dialog{ 

    public LoginDialog(Context context){ 
     super(context); 
    } 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.layout_login_dialog); 
    } 
} 
+1

你“想要”什么? –

+0

如果您试图控制对话框的大小,您应该阅读以下内容:http://stackoverflow.com/a/6631310/220710 –

+0

我希望对话框的宽度更大,例如正确的对话框 –

回答

0

您可以通过使用对话框的getwindow()方法获得对话框宽度,如...

WindowManager.LayoutParams lp=dialog.getWindow().getAttributes(); 

lp.width=300 or <your size> ; // for dialog width 
lp.x=700; // for dialog 
lp.y=10; // pos 
dialog.getWindow().setAttributes(lp); 
相关问题