设置 Android 操作栏颜色时出现“字段可以转换为局部变量”消息
2022-09-01 01:17:18
设置操作栏的颜色后,in 将突出显示为黄色,并且由于某种原因返回警告。可以做些什么来摆脱这个警告?actionBarColor
private String actionBarColor = "#B36305";
字段可以转换为局部变量
public class MainActivity extends AppCompatActivity {
private String actionBarColor = "#B36305";
private int getFactorColor(int color, float factor) {
float[] hsv = new float[3];
Color.colorToHSV(color, hsv);
hsv[2] *= factor;
color = Color.HSVToColor(hsv);
return color;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_activity_main);
ActionBar actionBar = getSupportActionBar();
if(actionBar != null) {
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor(actionBarColor)));
}
}
}