2010-11-03 31 views

Trả lời

-3

Thực hiện theo hoàn chỉnh xin vui lòng hướng dẫn http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 
    <ImageView 
     android:src="@drawable/header_logo" 
     android:layout_width="match_parent" 
     android:layout_height="64dp" 
     android:scaleType="center" 
     android:background="#FFFFBB33" 
     android:contentDescription="@string/app_name" /> 
    <EditText 
     android:id="@+id/username" 
     android:inputType="textEmailAddress" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="16dp" 
     android:layout_marginLeft="4dp" 
     android:layout_marginRight="4dp" 
     android:layout_marginBottom="4dp" 
     android:hint="@string/username" /> 
    <EditText 
     android:id="@+id/password" 
     android:inputType="textPassword" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="4dp" 
     android:layout_marginLeft="4dp" 
     android:layout_marginRight="4dp" 
     android:layout_marginBottom="16dp" 
     android:fontFamily="sans-serif" 
     android:hint="@string/password"/> 
</LinearLayout> 


@Override 
public Dialog onCreateDialog(Bundle savedInstanceState) { 
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 
    // Get the layout inflater 
    LayoutInflater inflater = getActivity().getLayoutInflater(); 

    // Inflate and set the layout for the dialog 
    // Pass null as the parent view because its going in the dialog layout 
    builder.setView(inflater.inflate(R.layout.dialog_signin, null)) 
    // Add action buttons 
      .setPositiveButton(R.string.signin, new DialogInterface.OnClickListener() { 
       @Override 
       public void onClick(DialogInterface dialog, int id) { 
        // sign in the user ... 
       } 
      }) 
      .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int id) { 
        LoginDialogFragment.this.getDialog().cancel(); 
       } 
      });  
    return builder.create(); 
} 
Các vấn đề liên quan