在 android 中设置按钮背景颜色的向后兼容性
Backward compatibility of setting the background color of a button in android
下面的代码显示了如何在API中设置按钮的背景颜色 23.如何获得与以前的API类似的功能?
Button aButton = (Button) findViewById(R.id.aButton);
aButton.setBackgroundColor(getResources().getColor(R.color.aColor));
使用ContextCompat.getColor(context, R.color.aColor)
。 ContextCompat 是支持库的一部分。
有关详细信息,请参阅 。
下面的代码显示了如何在API中设置按钮的背景颜色 23.如何获得与以前的API类似的功能?
Button aButton = (Button) findViewById(R.id.aButton);
aButton.setBackgroundColor(getResources().getColor(R.color.aColor));
使用ContextCompat.getColor(context, R.color.aColor)
。 ContextCompat 是支持库的一部分。
有关详细信息,请参阅