android控件-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.edittext01);
btn.setOnClickListener(new View.OnClickListener() {
private static final String TAG = "mm";
@Override
public void onClick(View view) {
String text = et.getText().toString();
Log.e(TAG, "onClick:"+text );
}
});
}
}
<EditText
android:id="@+id/edittext01"
android:hint="请输入用户名"
android:textColor="@color/black"
android:drawableLeft="@drawable/ic_baseline_people_alt_24"
android:drawablePadding="20dp"
android:layout_width="500px"
android:layout_height="300px"/>
<Button
android:text="我是按钮"
android:id="@+id/btn"
android:layout_width="200px"
android:layout_height="100px" />
点击按钮获取了结果
2022-04-21 12:25:57.724 17428-17428/com.example.myeidttext01 E/萌萌: onClick:hello😗rrrr
imageView图片适应组件布局
<ImageView
android:src="@drawable/test01"
android:layout_width="500dp"
android:layout_he