Colorful是一个动态主题库,允许您很容易地改变App的配色方案
在Application中初始化Colorful
public class SampleApp extends Application {
@Override
public void onCreate() {
super.onCreate();
Colorful.init(this);
}
}
如果你想设置默认的主题色,可以使用defaults()
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);
}
}
当然你也可以随时改变主题,只要调用一下apply()即可:
Colorful.config(this)
.primaryColor(Colorful.ThemeColor.RED)
.accentColor(Colorful.ThemeColor.BLUE)
.translucent(false)
.dark(true)
.apply();
想使用主题,还得让你的Activity继承CActivity:
public class MainActivity extends CActivity
Colorful内置了一个ColorPickerDialog,可以直接设置主题:
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();
}
}
Colorful还内置了一个preference可以自动设置主题
用colorpicker:primary_color & colorpicker:accent_color告诉Colorful设置哪个颜色。
<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"/>
github
https://github.com/garretyoder/Colorful
- 大小: 39.3 KB
- 大小: 38.5 KB
- Colorful-master.zip (120.7 KB)
- 下载次数: 0
- 查看图片附件