-
Notifications
You must be signed in to change notification settings - Fork 153
A Look at Storage Chooser.Theme
After 3 days of flowcharts and what not I found (I think I found) a better way to theme the storage-chooser more efficiently.
The way theming works now is by scheme. You set a color scheme to chooser which is an array (int[]) in your xml. For example:
<array name="paranoid_theme">
<!-- Overview -->
<item>#151515</item> <!-- Top Header bg -->
<item>#2c9633</item> <!-- header text -->
<item>#252525</item> <!-- list bg -->
<item>@android:color/white</item> <!-- storage list name text -->
<item>#e1e1e1</item> <!-- free space text -->
<item>#2c9633</item> <!-- memory bar -->
<!-- secondary dialog colors -->
<item>#151515</item> <!-- folder tint -->
<item>#252525</item> <!-- list bg -->
<item>@android:color/white</item> <!-- list text -->
<item>#151515</item> <!-- address bar tint -->
<item>@color/chevronBgColor</item> <!-- new folder hint tint -->
<item>#2c9633</item> <!-- select button color -->
<item>#da6c6c</item> <!-- new folder layour bg -->
<item>#2c9633</item> <!-- fab multiselect color -->
<item>#151515</item> <!-- address bar bg -->
</array>
Here I have created a color scheme called paranoid_theme
which can be then set to chooser by writing
StorageChooser.Theme theme = new StorageChooser.Theme(getApplicationContext());
theme.setScheme(getResources().getIntArray(R.array.paranoid_theme));
// and then passing it to builder instance
builder.setTheme(theme);
This way you can have multiple schemes of storage-chooser theme depending upon your use case. This is how paranoid_theme looks:
There are basically 2 default themes available for storage-chooser. Without the setTheme
method the theme used by storage-chooser will be default_light
color scheme which can be accessed by
theme.getDefaultTheme();
and another one is dark theme which follows your app color primarily with dark accent
theme.getDefaultDarkTheme()
both of them returns an int[]
.
Since theme.getDefaultTheme();
returns an int array it can be easily manipulated to create your own color scheme through code.
Say if you want to change only the list background to your desired color, you would do something like this
// use the theme instance created above
int[] myScheme = theme.getDefaultTheme();
// setting my own color for list backgrounds
// this is overview dialog list color
myScheme[StorageChooser.Theme.OVERVIEW_BG_INDEX] = getColor(R.color.list_bg);
// this is secondary dialog list color
myScheme[StorageChooser.Theme.SEC_BG_INDEX] = getColor(R.color.list_bg);
// now lets set your custom scheme
theme.setScheme(myScheme);
// apply it to chooser
builder.setTheme(theme);
Now you have your custom theme with your custom list background.