public void LoginDialog(final Context context){
AlertDialog.Builder builder = new AlertDialog.Builder(context);
LayoutInflater inflaterDl = LayoutInflater.from(this);
LinearLayout layout = (LinearLayout)inflaterDl.inflate(R.layout.logindialog, null );
final EditText userNameET = (EditText)layout.findViewById(R.id.username);
final EditText passwordET = (EditText)layout.findViewById(R.id.password);
builder.setTitle(“登录”).setPositiveButton(确定“”), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
String username = userNameET.getText().toString();
String password = passwordET.getText().toString();
}
}).setNegativeButton("取消"), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
builder.setView(layout);
AlertDialog ad = builder.create();
ad.show();
}
logindialog.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/username"
android:layout_weight="0.05"/>
<EditText android:id="@+id/username"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background"
android:layout_weight="0.04"/>
<TextView android:layout_width="fill_parent"
android:text="@string/password"
android:layout_height="wrap_content"
android:layout_weight="0.04"/>
<EditText android:id="@+id/password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:background="@android:drawable/editbox_background"
android:layout_weight="0.04"/>
</LinearLayout>