package com.example.myapplication; import android.os.Bundle; import android.text.Html; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; public class TextViewActivity extends MainActivity{ private Button btn1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.text); btn1=findViewById(R.id.denglu); btn1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Toast.makeText(TextViewActivity.this,"登陆成功",Toast.LENGTH_SHORT).show(); } }); } }
2.xml代码
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="10dp"> <EditText android:layout_width="match_parent" android:layout_height="50dp" android:text="" android:hint="用户名:" android:drawableLeft="@drawable/lianxiren" android:drawablePadding="10dp" android:maxLines="1" android:background="@drawable/button_shape" android:layout_marginTop="220dp"/> <EditText android:layout_width="match_parent" android:layout_height="50dp" android:layout_marginTop="40dp" android:background="@drawable/button_shape" android:drawableLeft="@drawable/chesuo" android:drawablePadding="10dp" android:hint="密码:" android:inputType="textPassword" android:maxLines="1" /> <Button android:id="@+id/denglu" android:layout_width="150dp" android:layout_height="wrap_content" android:text="点击登陆!" android:textSize="20dp" android:layout_marginLeft="115dp" android:background="@drawable/button_denglu" android:layout_marginTop="50dp"/> </LinearLayout>