标签:
UserUI:
===============================================================================================
代码实现:MainActivity.java
1 package com.example.a06_myui_01; 2 3 import android.os.Bundle; 4 import android.app.Activity; 5 import android.util.Log; 6 import android.view.Menu; 7 import android.view.View; 8 import android.view.View.OnClickListener; 9 import android.widget.Button; 10 import android.widget.EditText; 11 12 public class MainActivity extends Activity { 13 14 private EditText et; 15 private EditText et1; 16 17 /** 18 * TextView EditText 的属性可以在我们这个 <EditText android:id="@+id/etpwd" 19 * android:layout_width="match_parent" android:layout_height="wrap_content" 20 * android:hint="请输入密码" android:password="true" /> 21 */ 22 @Override 23 protected void onCreate(Bundle savedInstanceState) { 24 super.onCreate(savedInstanceState); 25 setContentView(R.layout.user); 26 et = (EditText) findViewById(R.id.etuser); 27 et1 = (EditText) findViewById(R.id.etpwd); 28 et.setHint("请输入邮箱"); 29 et.setText("admin"); 30 Button btn = (Button) findViewById(R.id.btlogin); 31 btn.setOnClickListener(new OnClickListener() { 32 33 @Override 34 public void onClick(View v) { 35 36 Log.i("Test", 37 "当前的用户:" + et.getText() + "当前的密码是:" + et1.getText()); 38 39 } 40 }); 41 42 } 43 }
==============================================================================================
user.xml:
1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:orientation="vertical" > 6 7 <LinearLayout 8 android:layout_width="match_parent" 9 android:layout_height="wrap_content" 10 android:layout_marginLeft="5dp" 11 android:layout_marginRight="24dp" 12 android:layout_marginTop="14dp" 13 android:orientation="horizontal" > 14 15 <TextView 16 android:layout_width="wrap_content" 17 android:layout_height="wrap_content" 18 android:text="账号:" 19 android:textSize="18sp" /> 20 21 <EditText 22 android:id="@+id/etuser" 23 android:layout_width="match_parent" 24 android:layout_height="wrap_content" 25 android:hint="请输入账号" /> 26 </LinearLayout> 27 28 <LinearLayout 29 android:layout_width="match_parent" 30 android:layout_height="wrap_content" 31 android:layout_marginBottom="40dp" 32 android:layout_marginLeft="5dp" 33 android:layout_marginRight="24dp" 34 android:layout_marginTop="20dp" 35 android:orientation="horizontal" > 36 37 <TextView 38 android:layout_width="wrap_content" 39 android:layout_height="wrap_content" 40 android:text="密码:" 41 android:textSize="18sp" /> 42 43 <EditText 44 android:id="@+id/etpwd" 45 android:layout_width="match_parent" 46 android:layout_height="wrap_content" 47 android:hint="请输入密码" 48 android:password="true" /> 49 </LinearLayout> 50 51 <LinearLayout 52 android:layout_width="match_parent" 53 android:layout_height="wrap_content" 54 android:layout_marginTop="40dp" > 55 56 <Button 57 android:id="@+id/btlogin" 58 android:layout_width="wrap_content" 59 android:layout_height="wrap_content" 60 android:layout_marginLeft="80dp" 61 android:text="登录" 62 android:textSize="18sp" /> 63 64 <Button 65 android:layout_width="wrap_content" 66 android:layout_height="wrap_content" 67 android:layout_marginLeft="40dp" 68 android:text="注册" 69 android:textSize="18sp" /> 70 </LinearLayout> 71 72 </LinearLayout>
标签:
原文地址:http://www.cnblogs.com/Je-Cortex/p/4830874.html