Android自定义登陆窗口

Android自定义登陆窗口-对话框

dilog.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:orientation="vertical">
   
  <TextView
      android:id="@+id/txt_loginerror"
      android:layout_height="wrap_content"
      android:layout_width="wrap_content"
      android:layout_marginLeft="20dip"
      android:layout_marginRight="20dip"
      android:textColor="#ff0000"
      android:text="输入的账号和密码不正确"
      android:gravity="left"
      android:textAppearance="?android:attr/textAppearanceMedium"
      android:visibility="invisible"
  />
 
 
  <TextView
      android:id="@+id/username"
      android:layout_height="wrap_content"
      android:layout_width="wrap_content"
      android:layout_marginLeft="20dip"
      android:layout_marginRight="20dip"
      android:text="账号"
      android:gravity="left"
      android:textAppearance="?android:attr/textAppearanceMedium"
  />
     
    <EditText
      android:id="@+id/txt_username"
      android:layout_height="wrap_content"
      android:layout_width="fill_parent"
      android:layout_marginLeft="20dip"
      android:layout_marginRight="20dip"
      android:autoText="false"
      android:capitalize="none"
      android:gravity="fill_horizontal"
      android:textAppearance="?android:attr/textAppearanceMedium"
      />
    <TextView
      android:id="@+id/password"
      android:layout_height="wrap_content"
      android:layout_width="wrap_content"
      android:layout_marginLeft="20dip"
      android:layout_marginRight="20dip"
      android:textAppearance="?android:attr/textAppearanceMedium"
      android:text="密码"
      android:gravity="left"
      />
    <EditText
      android:id="@+id/txt_password"
      android:layout_height="wrap_content"
      android:layout_width="fill_parent"
      android:layout_marginLeft="20dip"
      android:layout_marginRight="20dip"
      android:autoText="false"
      android:capitalize="none"
      android:gravity="fill_horizontal"
      android:textAppearance="?android:attr/textAppearanceMedium"
    />
   
        <TextView
      android:id="@+id/txt_toregister"
      android:layout_height="wrap_content"
      android:layout_width="wrap_content"
      android:layout_marginLeft="20dip"
      android:layout_marginRight="20dip"
      android:textColor="#2200C1"
      android:textAppearance="?android:attr/textAppearanceMedium"
      android:text="没有账号?快速注册"
      android:gravity="left"
      />
   
</LinearLayout>

代码里面:

<PRE class=java>private void CreateLoginAlert()
 {
  LayoutInflater factory = LayoutInflater.from(LoginActivity.this);
  //得到自定义对话框
    View DialogView = factory.inflate(R.layout.login_dialog, null);
         
  AlertDialog.Builder ad =new AlertDialog.Builder(this);
  ad.setTitle("账号登陆");       
  ad.setView(DialogView);   
  adi=  ad.create();
 
  adi.setButton("登录", new DialogInterface.OnClickListener() {
   
   @Override
   public void onClick(DialogInterface dialog, int which) {
    // TODO Auto-generated method stub
    username = (EditText)adi.findViewById(R.id.txt_username);
    password = (EditText)adi.findViewById(R.id.txt_password);
    loginerror = (TextView)adi.findViewById(R.id.txt_loginerror);
   
    m_Dilog=ProgressDialog.show(LoginActivity.this, "请等待...", "正在为你登陆...",true);
    mRedrawHandler.sleep(100);
   }
  });

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/9b00c9c377f238578ea061a15daca972.html