地址:https://github.com/garretyoder/Colorful
Colorful是一个简单又好用的帮助库,相对比为不同Activity设置不同主题(或者其他更复杂的情况),它允许你在任何时候用代码动态修改APP的基础颜色配置。
例如:
//可以全局设置
public class SampleApp extends Application { @Override public void onCreate() { super.onCreate(); Colorful.defaults() .primaryColor(Colorful.ThemeColor.RED) .accentColor(Colorful.ThemeColor.BLUE) .translucent(false) .dark(true); Colorful.init(this); }
}
//或者随便什么时候
Colorful.config(this) .primaryColor(Colorful.ThemeColor.RED) .accentColor(Colorful.ThemeColor.BLUE) .translucent(false) .dark(true)
.apply();
public class MainActivity extends CActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setSupportActionBar(((Toolbar) findViewById(R.id.toolbar))); ColorPickerDialog dialog = new ColorPickerDialog(this); dialog.setOnColorSelectedListener(new ColorPickerDialog.OnColorSelectedListener() { @Override public void onColorSelected(Colorful.ThemeColor color) { //TODO: Do something with the color } }); dialog.show(); } }Preference Item
Colorful has a inbuilt preference item that will automatically set Colorful's colors.
Use
colorpicker:primary_color
andcolorpicker:accent_color
to tell Colorful which value to set.<org.polaric.colorful.ColorPickerPreference android:title="@string/primary_color" android:summary="@string/primary_color_desc" colorpicker:primary_color="true"/> <org.polaric.colorful.ColorPickerPreference android:title="@string/accent_color" android:summary="@string/accent_color_desc" colorpicker:accent_color="true"/>Screenshots