今日总结
学习时间2h
重在坚持,代码如下
package com.app.chapter03;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import com.app.chapter03.utils.DateUtil;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
public class ButtonStyleActivity extends AppCompatActivity {
private TextView tv_result ;
private Button timebutton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_button_style);
/*TextView tv_result = findViewById(R.id.tv_result);//控件初始化*/
timebutton = findViewById(R.id.timebutton);
tv_result = findViewById(R.id.tv_result);
// 设置按钮点击监听器
timebutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// 在点击时获取当前时间并显示在 TextView 上
String currentTime = getCurrentTime();
String existingText = tv_result.getText().toString();
tv_result.setText(existingText + "\n" + currentTime);
}
});
}
private String getCurrentTime() {
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss", Locale.getDefault());
return sdf.format(new Date());
}
}
/* Button button = findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent =new Intent();
intent
}
});
}
}
public void doClick(View view){
String desc =String.format("%s 您点击了按钮: %s", DateUtil.getNowTime(),((Button)view).getText());
tv_result.setText(desc);
}
}*/
标签:androidx,tv,result,new,import,5.28,View From: https://www.cnblogs.com/tianpeisen/p/18250882