今日总结
学习时间2h致力于android的学习 无法自拔
package com.app.chapter03;标签:text,Button,5.26,import,android,btn,id From: https://www.cnblogs.com/tianpeisen/p/18250872
import android.graphics.Color;
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;
public class ButtonEnableActivity extends AppCompatActivity implements View.OnClickListener {
private Button btn_text;
private TextView tv_result;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_button_enable);
Button btn_enable = findViewById(R.id.btn_enable);
Button btn_disable = findViewById(R.id.btn_disable);
tv_result = findViewById(R.id.tv_result);
Button btn_text = findViewById(R.id.btn_text);
btn_enable.setOnClickListener(this);
btn_disable.setOnClickListener(this);
btn_text.setOnClickListener(this);
}
@Override
public void onClick(View v) {
Button btn_text = findViewById(R.id.btn_text);
if (v.getId() == R.id.btn_enable) {
btn_text.setEnabled(true);
btn_text.setTextColor(Color.BLACK);
} else if (v.getId() == R.id.btn_disable) {
btn_text.setEnabled(false);
btn_text.setTextColor(Color.GRAY);
}if(v.getId() == R.id.btn_text){
String desc =String.format("%s 您点击了按钮: %s", DateUtil.getNowTime(), ((Button)v).getText());
tv_result.setText(desc);
}
}
}