Article directory
File Directory
activity_main.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">
<EditText
android:hint="请输入用户名"
android:id="@+id/et"
android:layout_width="200dp"
android:layout_height="100dp"
android:textColorHint="#95a1aa"
android:inputType="phone"
/>
<EditText
android:hint="请输入用户名"
android:layout_width="200dp"
android:layout_height="100dp"
android:textColorHint="#95a1aa"
android:inputType="numberPassword"
android:drawableLeft="@drawable/ic_baseline_account_box_24"
android:drawablePadding="20dp"
android:paddingLeft="10dp"
android:background="@color/white"
/>
<Button
android:id="@+id/btn"
android:text="获取用户名"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
android:hint is the content of the text box initialization (it will disappear after input)
android:inputType The type of the text box, which is set to a digital type (can be set to other types, crtl + that line of code can go in and see the properties) .
android:drawableLeft sets the picture on the left
android:background sets the background color
...
ic_baseline_account_box_24.xml
Is the inserted vector
<vector android:height="24dp" android:tint="#43805B"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M3,5v14c0,1.1 0.89,2 2,2h14c1.1,0 2,-0.9 2,-2L21,5c0,-1.1 -0.9,-2 -2,-2L5,3c-1.11,0 -2,0.9 -2,2zM15,9c0,1.66 -1.34,3 -3,3s-3,-1.34 -3,-3 1.34,-3 3,-3 3,1.34 3,3zM6,17c0,-2 4,-3.1 6,-3.1s6,1.1 6,3.1v1L6,18v-1z"/>
</vector>
Can be inserted by itself or directly copied
MainActivity
package zufe.scq.hunter;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
private EditText et;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn = findViewById(R.id.btn);
et = findViewById(R.id.et);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String text = et.getText().toString();
Log.e("btn", text);
}
});
}
}
GetText can get the content inside
Click Run
Enter username:
Click the Get Username button
to see the output in the console: