有勇气的牛排博客

安卓 常用控件 监听 事件

有勇气的牛排 1084 安卓 2021-10-17 00:47:33

< RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="${relativePackage}.${activityClass}" > < TextView android:id="@+id/One" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:text="One" tools:ignore="MissingConstraints" tools:layout_editor_absoluteX="104dp" tools:layout_editor_absoluteY="116dp" /> < EditText android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_marginLeft="7dp" android:layout_marginTop="32dp" android:ems="10" android:text="输入用户名"> < /EditText> < EditText android:id="@+id/editText2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/editText1" android:layout_marginTop="19dp" android:ems="10" android:text="密码" /> < Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/editText2" android:layout_marginLeft="243dp" android:text="Button" /> < /RelativeLayout>
TextView textView1; EditText edit1; EditText edit2; Button btn1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); textView1 = findViewById(R.id.One); edit1 = (EditText) findViewById(R.id.editText1); edit2 = (EditText) findViewById(R.id.editText2); btn1 = (Button) findViewById(R.id.button1); btn1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String username = edit1.getText().toString(); String password = edit2.getText().toString(); textView1.setText(username); textView1.setTextColor(Color.RED); textView1.setTextSize(20); } }); }

留言

专栏
文章
加入群聊