Toast弹窗。Editext常用属性。drawable 点击,描边

Toast:弹窗

package com.example.newthree;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class EditTextActivity extends AppCompatActivity {
    //声明控件
    private Button mlogin;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_edit_text);
        //找到控件
        mlogin=findViewById(R.id.btn_1);
        //设置点击
        mlogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //执行
                Toast.makeText(EditTextActivity.this,"登录成功",Toast.LENGTH_LONG).show();
            }
        });
    }
}

相对布局,和EdiText常用属性

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="10dp">

    <EditText
        android:id="@+id/et_1"
        android:layout_width="match_parent"
        android:layout_height="70dp"
        android:hint="用户名"
        android:drawablePadding="5dp"
        android:drawableLeft="@drawable/science"
        android:inputType="number"
        android:background="@drawable/user"
        android:paddingRight="10dp"
        android:paddingLeft="10dp"
        android:textColor="@color/black"/>

    <EditText
        android:id="@+id/et_2"
        android:layout_width="match_parent"
        android:layout_height="70dp"
        android:paddingRight="10dp"
        android:paddingLeft="10dp"
        android:hint="密码"
        android:drawableLeft="@drawable/teacher"
        android:drawablePadding="5dp"
        android:background="@drawable/user"
        android:layout_marginTop="30dp"
        android:inputType="textPassword"
        android:textColor="@color/black"
        android:layout_below="@+id/et_1"/>
    <Button
        android:id="@+id/btn_1"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_marginLeft="50dp"
        android:layout_marginRight="50dp"
        android:layout_marginTop="20dp"
        android:background="@drawable/press"
        android:text="登录"
        android:layout_below="@id/et_2"/>

</RelativeLayout>

drawable效果,点击

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true">
        <shape>
            <corners android:radius="10dp" />
            <solid android:color="#EBF3A2" />
        </shape>
    </item>
    <item android:state_pressed="false">
        <shape>
            <corners android:radius="10dp" />
            <solid android:color="#D2E60F" />
        </shape>
    </item>


</selector>

drawable,描边

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners android:radius="10dp" />
    <stroke
        android:width="1dp"
        android:color="#999999" />

</shape>

上一篇:Android:涂鸦sdk用户注册登录流程


下一篇:在AndroidStudio中使用OpenCV总结