EditText(文本输入)
<Button
android:id="@+id/btn_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:layout_marginLeft="170dp"
android:layout_marginTop="10dp"
/>
java控制点击事件发生,跳转到onclickLogin_jump
private Button BtnLogin;
BtnLogin = findViewById(R.id.btn_login);
BtnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(testView.this, onclickLogin_jump.class); // 跳转到登录界面
startActivity(intent);
}
});
用户名代码如下:
<EditText
android:id="@+id/textview_usename"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="30dp"
android:textColor="#DF01D7"
android:hint="用户名"
android:textColorHint="#C1A1A107"
android:layout_marginTop="60dp"
android:layout_marginLeft="60dp"
android:layout_marginRight="60dp"
android:background="@drawable/btn0912"
/>
默认提示文字:android:hint = "密码"
默认提示文字颜色:android:textColorHint="#C1A1A107"
暗文:inputType = "textPassword"
弹出手机号:android:inputType = "number"
设置背景:android:background="@drawable/btn0912",代码如下:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape>
<solid
android:color="#06A4BA"
/>
<corners
android:radius="10dp"
/>
</shape>
</item>
<item android:state_pressed="false">
<shape>
<solid
android:color="#B5F0F8"
/>
<corners android:radius="5dp"
/>
</shape>
</item>
</selector>
密码代码如下:
<EditText
android:layout_below="@+id/textview_usename"
android:id="@+id/textview_password"
android:inputType="textPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="30dp"
android:textColor="#999999"
android:hint="密码"
android:textColorHint="#FF5722"
android:layout_marginTop="20dp"
android:layout_marginLeft="60dp"
android:layout_marginRight="60dp"
android:background="@drawable/btn_2_0912"
/>
提交按钮代码如下:
<Button
android:layout_below="@+id/textview_password"
android:id="@+id/textview_submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="提交"
android:layout_marginLeft="150dp"
android:layout_marginTop="40dp"/>
java代码控制提交按钮点击事件发生:
private Button btnSummit;
btnSummit = findViewById(R.id.textview_submit);
btnSummit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(onclickLogin_jump.this,"您已登录成功!",Toast.LENGTH_LONG).show();
}
});
监听用户密码的改变(日志文件中):
textPasswordchange = findViewById(R.id.textview_password);
textPasswordchange.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
// 此方法常用
Log.d("edittext",charSequence.toString()); // 打印输入的内容日志
}
@Override
public void afterTextChanged(Editable editable) {
}
});
本文地址:https://blog.csdn.net/m0_47119598/article/details/108585273