提交 6df111db 编写于 作者: K khz_pc

测试程序修改

上级 275c29b6
...@@ -2,13 +2,75 @@ package com.ninecents; ...@@ -2,13 +2,75 @@ package com.ninecents;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Color;
import android.os.Bundle; import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity { public class MainActivity extends AppCompatActivity implements View.OnClickListener {
Button button_member_method;
Button button_static_method;
Button button_overload_method;
static MainActivity _this;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
// 绑定事件
button_member_method = (Button) findViewById(R.id.button_member_method);
button_member_method.setOnClickListener(this);
button_static_method = (Button) findViewById(R.id.button_static_method);
button_static_method.setOnClickListener(this);
button_overload_method = (Button) findViewById(R.id.button_overload_method);
button_overload_method.setOnClickListener(this);
_this = this;
}
private int _member_method(String text) {
Toast.makeText(getApplicationContext(),text,Toast.LENGTH_SHORT).show();
// 返回值为0:展示红色,否则展示蓝色
return 0;
}
private static void _static_method() {
Toast.makeText(MainActivity._this,"button_static_method",Toast.LENGTH_SHORT).show();
}
private void _overload_method(String text) {
Toast.makeText(getApplicationContext(),text,Toast.LENGTH_SHORT).show();
}
private void _overload_method(int val) {
String text;
if (val == 1) {
text = "111111111";
} else {
text = "222222222";
}
Toast.makeText(getApplicationContext(),text,Toast.LENGTH_SHORT).show();
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.button_member_method:
int ret = _member_method("这是button_member_method");
if (ret == 0) {
button_member_method.setBackgroundColor(Color.parseColor("#FF0000"));
} else {
button_member_method.setBackgroundColor(Color.parseColor("#0000FF"));
}
break;
case R.id.button_static_method:
MainActivity._static_method();
break;
case R.id.button_overload_method:
_overload_method(1);
break;
}
} }
} }
\ No newline at end of file
...@@ -7,12 +7,35 @@ ...@@ -7,12 +7,35 @@
tools:context=".MainActivity"> tools:context=".MainActivity">
<TextView <TextView
android:id="@+id/hello"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="96px"
android:text="Hello World!" android:text="Hello Frida!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button_member_method"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="成员函数"
app:layout_constraintTop_toBottomOf="@+id/hello"
app:layout_constraintLeft_toLeftOf="parent" />
<Button
android:id="@+id/button_static_method"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="静态函数"
app:layout_constraintTop_toBottomOf="@+id/button_member_method"
app:layout_constraintLeft_toLeftOf="parent" />
<Button
android:id="@+id/button_overload_method"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="重载函数"
app:layout_constraintTop_toBottomOf="@+id/button_static_method"
app:layout_constraintLeft_toLeftOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册