java:
MainActivity
package cn.studyjams.s1.sj101.myapplication; import android.app.Activity; import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.TextView; public class MainActivity extends Activity { private TextView textView; //private View mview; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);//加载第一个布局 textView=(TextView) findViewById(R.id.Text1);//获取注册这个文本控件 textView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //获取当前类和要跳转的布局传给一个View类view布局控件 View view=View.inflate(MainActivity.this,R.layout.activity_main2,null); //创建对话框 AlertDialog.Builder mAlertDialog=new AlertDialog.Builder(MainActivity.this); //给对话框赋view mAlertDialog.setView(view); //显示对话框 mAlertDialog.show(); } }); } }MainActivity2
package cn.studyjams.s1.sj101.myapplication; import android.app.Activity; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; /** * Created by Administrator on 2016/10/27. */ public class MainActivity2 extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main2); } }
Xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="cn.studyjams.s1.sj101.myapplication.MainActivity" android:background="@drawable/oo" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="门禁管理系统" android:textColor="#c0c0c0" android:textSize="16dp" /> <TextView android:text="注册" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:textSize="16dp" android:textColor="#c0c0c0" android:id="@+id/Text1" android:onClick="text" /> <ImageView android:layout_width="20dp" android:layout_height="20dp" android:layout_toLeftOf="@id/Text1" android:background="@drawable/ii" /> <RelativeLayout android:layout_width="200dp" android:layout_height="500dp" android:layout_below="@id/Text1" android:layout_marginTop="10dp" android:background="#ffffff" android:id="@+id/Rela1" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:id="@+id/line1" > <TextView android:text="读 卡:" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10dp" /> <EditText android:layout_width="80dp" android:layout_height="wrap_content" android:background="@drawable/ff" /> <Button android:text="读卡" android:layout_width="55dp" android:layout_height="20dp" android:background="@drawable/qq" android:textColor="#ffffff" android:layout_marginLeft="5dp" /> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:layout_below="@+id/line1" android:paddingLeft="10dp" android:id="@+id/line2" > <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:text="照 片:" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" /> <ImageView android:layout_width="40dp" android:layout_height="40dp" android:src="@drawable/w" android:layout_marginLeft="20dp" /> </LinearLayout> <TextView android:text="姓 名:" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="10dp" /> <TextView android:text="职 务:" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="10dp" /> <TextView android:text="电 话:" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="10dp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/line2" android:paddingLeft="10dp" android:orientation="horizontal" android:id="@+id/line3" android:layout_marginTop="5dp" > <TextView android:text="密 码:" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/ff" android:layout_marginRight="20dp" /> </LinearLayout> <Button android:text="开门" android:layout_width="match_parent" android:layout_height="30dp" android:background="@drawable/ee" android:layout_below="@+id/line3" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:textColor="#ffffff" android:layout_marginTop="10dp" /> </RelativeLayout> <ImageView android:layout_width="wrap_content" android:layout_height="200dp" android:layout_toRightOf="@id/Rela1" android:src="@drawable/qqq" android:layout_marginTop="50dp" android:layout_marginLeft="50dp" /> </RelativeLayout>
XMl2
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#0033cc" > <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/line1" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/text" android:layout_centerHorizontal="true" android:textColor="#ffffff" android:layout_marginTop="10dp" android:id="@+id/text" /> </RelativeLayout> <LinearLayout android:id="@+id/line2" android:layout_width="320dp" android:layout_height="wrap_content" android:background="#3399ff" android:orientation="vertical" android:layout_below="@+id/line1" android:layout_marginTop="20dp" > <TextView android:text="姓名" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="10dp" android:paddingLeft="5dp" android:textColor="#cccccc" /> <View android:layout_width="fill_parent" android:layout_height="1px" android:background="#ffffff" android:layout_margin="5dp" > </View> <TextView android:text="职位" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="10dp" android:paddingLeft="5dp" android:textColor="#cccccc" /> <View android:layout_width="fill_parent" android:layout_height="1px" android:background="#ffffff" android:layout_margin="5dp" > </View> <TextView android:text="电话" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="10dp" android:paddingLeft="5dp" android:textColor="#cccccc" /> <View android:layout_width="fill_parent" android:layout_height="1px" android:background="#ffffff" android:layout_margin="5dp" > </View> <TextView android:text="密码" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="10dp" android:paddingLeft="5dp" android:textColor="#cccccc" /> <View android:layout_width="fill_parent" android:layout_height="1px" android:background="#ffffff" android:layout_margin="5dp" > </View> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:text="卡号" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="10dp" android:paddingLeft="5dp" android:textColor="#cccccc" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" /> <Button android:layout_width="wrap_content" android:layout_height="40dp" android:layout_gravity="right" android:text="读卡" android:layout_alignParentRight="true" /> </RelativeLayout> <View android:layout_width="fill_parent" android:layout_height="1px" android:background="#ffffff" > </View> </LinearLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_toRightOf="@id/line2" > <ImageView android:layout_width="110dp" android:layout_height="70dp" android:src="@drawable/r" android:layout_marginTop="100dp" android:layout_centerHorizontal="true" android:id="@+id/image" android:layout_marginBottom="10dp" /> <Button android:text="注册" android:layout_width="130dp" android:layout_height="wrap_content" android:layout_below="@+id/image" android:layout_centerHorizontal="true" android:background="@drawable/qq" android:textColor="#ffffff" /> </RelativeLayout> </RelativeLayout>
drawable xml:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#ff0033"/> <corners android:radius="10dp" /> </shape>
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#ffffff"/> <corners android:radius="5dp" /> <stroke android:width="1dp" android:color="#bdc7d8" /> <!--stroke 描边--> </shape>
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#0000ff"/> <corners android:radius="10dp" /> </shape>