java - 有没有办法压缩重复的颜色设置?
问题描述
如您所知,我们可以使用int a,b,c=3;
而不是:
int a;
int b;
int c=3;
我使用了很多代码,如下所示。例如更改视图或其他设置。它浪费了我很多时间。有没有办法让它变得更容易?
//<editor-fold desc="Not Dark Mode">
Button Save=findViewById(R.id.Setting_Save_BTN);
Button Back=findViewById(R.id.Setting_Back_BTN);
Button Instruction=findViewById(R.id.Setting_Instruction_BTN);
TextView Title=findViewById(R.id.Setting_Title_TXT);
TextView Display=findViewById(R.id.Setting_Display_TXT);
TextView Progress=findViewById(R.id.Setting_Progress_Bar_TXT);
TextView Relaps=findViewById(R.id.Setting_Relaps_TXT);
TextView Lang=findViewById(R.id.Setting_Language_TXT);
findViewById(R.id.Setting_Layout).setBackgroundColor(Color.WHITE);
Phone_Language.setTextColor(Color.BLACK);
Persian.setTextColor(Color.BLACK);
Arabic.setTextColor(Color.BLACK);
English.setTextColor(Color.BLACK);
Spanish.setTextColor(Color.BLACK);
Hindi.setTextColor(Color.BLACK);
Malay.setTextColor(Color.BLACK);
Portuguese.setTextColor(Color.BLACK);
Russian.setTextColor(Color.BLACK);
Chinese.setTextColor(Color.BLACK);
.
.
.
OnePhase.setTextColor(Color.BLACK);
ThreePhase.setTextColor(Color.BLACK);
Save.setTextColor(Color.BLACK);
Back.setTextColor(Color.BLACK);
Relaps.setTextColor(Color.BLACK);
Lang.setTextColor(Color.BLACK);
//</editor-fold>
如果你能回答我,我将不胜感激...
解决方案
您可以使用循环删除重复。
TextView[] makeBlack = new TextView [] {
Persian, Arabic, English, Spanish,
Hindi, Malay // add the rest
};
for (TextView view: makeBlack) {
view.setTextColor(Color.BLACK);
}
推荐阅读
- c# - 使用 Microsoft Playwright 在 Azure Function Linux 消费计划中创建本地 PDF 文件
- c# - 使用 C# 在 BigQuery 中组合非平面架构
- search - Parallelizing search in a 2D array on CUDA
- bash - 在 bash 变量中使用 find 计算找到的路径数
- logging - 寻找一种在simulation.log文件中向Gatling事务添加更多信息的方法
- ansible - jinja2 中缺少变量,Ansible 没有输出
- typescript - 为赛普拉斯指定 tsconfig.json 位置
- sql - 在 sequelize 中定义与自引用表的 belongsToMany 关系
- php - DKIM“失败”(签名错误)
- reactjs - 对齐文本和图像的问题,反应js material-ui