2020.10.1
阿新 • • 發佈:2020-12-06
<?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:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_marginTop="200dp" > <EditText android:id="@+id/etiname" android:layout_width="200dp" android:layout_height="wrap_content" android:layout_marginLeft="40dp" android:hint="輸入使用者名稱" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="使用者名稱" android:textSize="28dp" android:layout_marginLeft="40dp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_marginTop="20dp" > <EditText android:id="@+id/edimima" android:layout_width="200dp" android:layout_height="wrap_content" android:layout_marginLeft="40dp" android:hint="輸入密碼" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="40dp" android:text="密碼" android:textSize="28dp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:layout_marginTop="80dp" > <Button android:id="@+id/btn_one" android:layout_marginLeft="100dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="登陸" android:onClick="onclick2" tools:ignore="OnClick" /> </LinearLayout> </LinearLayout>
package com.example.myapplication1; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class MainActivity extends AppCompatActivity implements View.OnClickListener{ private Button btn_one; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setContentView(R.layout.activity_main); btn_one =(Button)findViewById(R.id.btn_one); btn_one.setOnClickListener(new View.OnClickListener(){ public void onClick(View View){ btn_one.setText("按鈕被點選"); } }) } }