今日总结
学习时间2h
代码如下
package com.app.chapter03;标签:code,androidx,tv,eight,import,android,5.29 From: https://www.cnblogs.com/tianpeisen/p/18250884
import android.content.Intent;
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;
public class TextColorActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_text_color);
//从布局文件中获取名叫tv_code_system的文本视图
TextView tv_code_system=findViewById(R.id.tv_code_system);
//将tv_code_system设置为系统自带的绿色
tv_code_system.setTextColor(Color.GREEN);
//从布局文件中获取名叫tv_code_eight的8位文本视图
TextView tv_code_eight=findViewById(R.id.tv_code_eight);
//将tv_code_eight设置为不透明绿色,正常绿色。
tv_code_eight.setTextColor(0xff00ff00);
//从布局文件中获取名叫tv_code_six的6位文本视图
TextView tv_code_six=findViewById(R.id.tv_code_six);
//将tv_code_six设置为不透明绿色,正常绿色。
tv_code_eight.setTextColor(0x00ff00);
//从布局中获取tv_code_background
TextView tv_code_background= findViewById(R.id.tv_code_background);
//tv_code_background.setBackgroundColor(Color.GREEN);
tv_code_background.setBackgroundResource(R.color.green);
Button button =findViewById(R.id.跳转);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent= new Intent();
intent.setClass(TextColorActivity.this,ButtonLongClickActivity.class);
startActivity(intent);
}
});
}
}