android开发分享Android开发布局 案例二

实践案例:XML<?xml version=”1.0″ encoding=”utf-8″?><LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:app=”http://schemas.android.com/apk/res-auto” xmlns:tools=”http://schemas.android.com/tools” android:l


实践案例:

Android开发布局 案例二

XML

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="https://schemas.android.com/apk/res/android"     xmlns:app="https://schemas.android.com/apk/res-auto"     xmlns:tools="https://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:orientation="vertical"     tools:context="登录">      <android.support.v7.widget.AppCompatEditText         android:id="@+id/UserName"         android:layout_width="match_parent"         android:layout_height="60dp"         android:text="请输入用户名" />      <android.support.v7.widget.AppCompatEditText         android:id="@+id/UserPassWord"         android:layout_width="match_parent"         android:layout_height="60dp"         android:text="请输入密码" />      <android.support.v7.widget.AppCompatButton         android:id="@+id/Login"         android:layout_width="match_parent"         android:layout_height="60dp"         android:text="登录" />      <TextView         android:id="@+id/TextView"         android:layout_width="wrap_content"         android:layout_height="wrap_content" />      <CheckBox         android:id="@+id/checkBox"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:text="记住密码" />  </LinearLayout>

Java

package com.example.administrator.demo2;  import android.app.AlertDialog; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView;  public class MainActivity extends AppCompatActivity {      @Override     protected void onCreate(Bundle savedInstanceState) {         //调用父类的onCreate方法         super.onCreate(savedInstanceState);         //设置layout中对应的XML文件activity_main         setContentView(R.layout.activity_main);         //获取登录按钮         Button ligin_button = (Button) findViewById(R.id.Login);         //获取文本框控件         final EditText userName_edt = (EditText) findViewById(R.id.UserName);         final EditText userPass_edt = (EditText) findViewById(R.id.UserPassWord);         //设置“登录”按钮的监听事件         ligin_button.setOnClickListener(new View.OnClickListener() {             @Override             public void onClick(View v) {                 String userName = userName_edt.getText().toString();                 String userPass = userName_edt.getText().toString();                 //获取Text控件                 TextView tv = (TextView) findViewById(R.id.TextView);                 //设置Text为本两个文本框的内容                 tv.setText("您的用户名是:"+userName+"密码是:"+userPass);                 //设置点击登录按钮后跳转到其他地方                 Intent it = new Intent();                 it.setClass(MainActivity.this,Main2Activity.class);                 startActivity(it);              }         });     } } 

 

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/addevelopment/892676.html

(0)
上一篇 2021年10月20日
下一篇 2021年10月20日

精彩推荐