{"id":13643556,"url":"https://github.com/afollestad/aesthetic","last_synced_at":"2025-09-28T21:31:06.631Z","repository":{"id":72569507,"uuid":"90922472","full_name":"afollestad/aesthetic","owner":"afollestad","description":"[DEPRECATED]","archived":true,"fork":false,"pushed_at":"2019-08-08T23:51:30.000Z","size":45804,"stargazers_count":1995,"open_issues_count":14,"forks_count":214,"subscribers_count":58,"default_branch":"master","last_synced_at":"2024-11-24T17:47:50.906Z","etag":null,"topics":["android","androidx","dynamic","engine","kotlin","reactive","runtime","rx","theme","theme-color","theme-properties"],"latest_commit_sha":null,"homepage":"https://af.codes","language":"Kotlin","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/afollestad.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-05-11T01:10:04.000Z","updated_at":"2024-09-29T13:18:59.000Z","dependencies_parsed_at":"2023-05-16T14:00:57.358Z","dependency_job_id":null,"html_url":"https://github.com/afollestad/aesthetic","commit_stats":null,"previous_names":[],"tags_count":32,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afollestad%2Faesthetic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afollestad%2Faesthetic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afollestad%2Faesthetic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afollestad%2Faesthetic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/afollestad","download_url":"https://codeload.github.com/afollestad/aesthetic/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234563141,"owners_count":18853060,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","androidx","dynamic","engine","kotlin","reactive","runtime","rx","theme","theme-color","theme-properties"],"created_at":"2024-08-02T01:01:49.193Z","updated_at":"2025-09-28T21:31:00.805Z","avatar_url":"https://github.com/afollestad.png","language":"Kotlin","funding_links":[],"categories":["主题样式","Theme / Skin"],"sub_categories":[],"readme":"# Aesthetic\n\n/esˈTHedik/: *adjective*, concerned with beauty or the appreciation of beauty. \n\n[ ![jCenter](https://api.bintray.com/packages/drummer-aidan/maven/aesthetic/images/download.svg) ](https://bintray.com/drummer-aidan/maven/aesthetic/_latestVersion)\n[![Build Status](https://travis-ci.org/afollestad/aesthetic.svg)](https://travis-ci.org/afollestad/aesthetic)\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/b085aa9e67d441bd960f1c6abce5764c)](https://www.codacy.com/app/drummeraidan_50/aesthetic?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=afollestad/aesthetic\u0026amp;utm_campaign=Badge_Grade)\n[![License](https://img.shields.io/badge/license-Apache%202-4EB1BA.svg?style=flat)](https://www.apache.org/licenses/LICENSE-2.0.html)\n\nYou can download an \u003ca href=\"https://raw.githubusercontent.com/afollestad/aesthetic/master/sample.apk\"\u003eAPK of the sample project\u003c/a\u003e.\n\n\u003cimg src=\"https://raw.githubusercontent.com/afollestad/aesthetic/master/images/1.jpg\" width=\"800\" /\u003e\n\n---\n\n# Table of Contents\n\n1. [Gradle Dependency](#gradle-dependency)\n2. [Integration](#integration)\n3. [Configuration](#configuration)\n4. [Attributes](#attributes)\n    1. [Base Values](#base-values)\n    2. [Standard Colors](#standard-colors)\n    3. [Standard Text Colors](#standard-text-colors)\n    4. [Custom Attributes](#custom-attributes)\n5. [Advanced Views](#advanced-views)\n    1. [Toolbars](#toolbars)\n    2. [Snackbars](#snackbars)\n    3. [CardViews](#cardviews)\n    4. [TabLayouts](#tablayouts)\n    5. [BottomNavigationViews](#bottomnavigationviews)\n    6. [NavigationViews](#navigationviews)\n    7. [SwipeRefreshLayouts](#swiperefreshlayouts)\n6. [Custom Views and Manual Application](#custom-views-and-manual-application)\n7. [Ignoring Views](#ignoring-views)\n\n---\n\n# Gradle Dependency\n\nAdd this to your app module's `build.gradle` file:\n\n```gradle\ndependencies {\n  \n  implementation 'com.afollestad:aesthetic:1.0.0-beta05'\n}\n```\n\n---\n\n# Integration\n\nAesthetic is integrated at a per-Activity level. The simplest way is \nto have your Activities extend `AestheticActivity`.\n\n```kotlin\nclass MyActivity : AestheticActivity() {\n\n  override fun onCreate(savedInstanceState: Bundle?) {\n    super.onCreate(savedInstanceState)\n  }\n}\n```\n\nIf you *don't want to or cannot extend this class*, you can manually \ntell Aesthetic about lifecycle events:\n\n```kotlin\nclass MyActivity : AppCompatActivity() {\n\n  override fun onCreate(savedInstanceState: Bundle?) {\n    Aesthetic.attach(this)  // MUST come before super.onCreate(...)\n    super.onCreate(savedInstanceState)\n  }\n\n  override fun onResume() {\n    super.onResume()\n    Aesthetic.resume(this)\n  }\n\n  override fun onPause() {\n    Aesthetic.pause(this)\n    super.onPause()\n  }\n}\n```\n\n---\n\n# Configuration\n\nAesthetic provides a `isFirstTime` field which returns true until \nyou apply theme configuration at least once.\n\nYou can use this to setup defaults on app launch.\n\n```kotlin\nclass MyActivity : AestheticActivity() {\n\n  override fun onCreate(savedInstanceState: Bundle?) {\n    super.onCreate(savedInstanceState)\n    \n    // If we haven't set any defaults, do that now\n    if (Aesthetic.isFirstTime) {\n        Aesthetic.config {\n          ...\n        }\n    }\n  }\n}\n```\n\nThere are two ways to \"configure\" Aesthetic, with the `config` method:\n\n```kotlin\nAesthetic.config {\n  colorPrimaryRes(R.color.blue)\n  ...\n}\n```\n\nOr by chaining the setters and calling `apply()`:\n\n```kotlin\nAesthetic.get()\n  .colorPrimaryRes(R.color.blue)\n  ...\n  .apply() // don't forget apply() with this way\n```\n\n*If you are using Java*, you cannot use the `config` method.\n\n---\n\n# Attributes\n\nAttributes are the foundation of this library. They link your UI to dynamically changing colors.\n\nAttributes exist natively on Android, but they are not dynamic - they are rather set in your Activity \nthemes and are pre-determined at compile-time. This library gets around that.\n\n### Base Values\n\n```kotlin\nAesthetic.config {\n  // Set to false for light themes, true for dark.\n  // By default, is based on whether textColorPrimary is light/dark.\n  isDark(false)\n  \n  // Causes an Activity recreate, calls setTheme(Int) on it.\n  activityTheme(R.style.MyActivityTheme)\n  \n  // ON makes status bar icons black, and vice versa. AUTO bases it on \n  // the status bar color, e.g. white -\u003e light mode, black -\u003e normal mode.\n  // This has no effect below API 23 (Marshmallow). \n  lightStatusBarMode(AutoSwitchMode.AUTO)\n  \n  // ON makes navigation bar icons black, and vice versa. AUTO bases it on \n  // the navigation bar color, e.g. white -\u003e light mode, black -\u003e normal mode.\n  // This has no effect below API 26 (Oreo).\n  lightNavigationBarMode(AutoSwitchMode.AUTO)\n}\n```\n\n---\n\n### Standard Colors\n\n```kotlin\nAesthetic.config {\n  // ?colorPrimary, used for Toolbars, etc.\n  colorPrimaryRes(R.color.blue)\n  // ?colorPrimaryDark, used for status bars, etc.\n  colorPrimaryDark(R.color.blue)\n  // ?colorAccent, used for input fields, buttons, etc.\n  colorAccentRes(R.color.blue)\n  \n  // Defaults to colorPrimaryDark.\n  colorStatusBarRes(R.color.blue)\n  // Sets to colorPrimaryDark. \n  colorStatusBarAuto() \n  \n  // Defaults to the value in your activity theme, or black.\n  colorNavigationBarRes(R.color.blue)\n  // Sets nav bar color to match ?colorPrimaryDark. \n  // If the color is light and light nav bar mode is disabled, it is forced to black.\n  colorNavigationBarAuto()\n  \n  // Defaults to the value in your activity theme.\n  colorWindowBackgroundRes(R.color.blue)\n}\n```\n\nThe methods which end with `Res` take a color resource. Remove `Res` to \npass a literal (hardcoded) color integer.\n\n---\n\n### Standard Text Colors\n\n```kotlin\nAesthetic.config {\n  // ?android:textColorPrimary\n  textColorPrimaryRes(R.color.black)\n  // ?android:textColorSecondary\n  textColorSecondaryRes(R.color.dark_gray)\n  \n  // ?android:textColorPrimaryInverse\n  textColorPrimaryInverseRes(R.color.white)\n  // ?android:textColorSecondaryInverse\n  textColorSecondaryInverseRes(R.color.light_gray)\n}\n```\n\nThe methods which end with `Res` take a color resource. Remove `Res` to \npass a literal (hardcoded) color integer.\n\n---\n\n### Custom Attributes\n\nAll of the \"attributes\" shown and used in examples above are shown with shortcut methods that \nassign a color to a specific pre-existing attribute, such as `colorPrimary` from AndroidX.\n\nYou can define custom attributes that are usable in layouts. You can \nassign colors to theme like you would the predefined attributes above.\n\nFirst, you need to define the attribute in `/values/attrs.xml`:\n\n```xml\n\u003cresources\u003e\n  \u003cattr format=\"color\" name=\"my_custom_attr\"/\u003e\n\u003c/resources\u003e\n```\n\nThen you need to define a default in your Activity's theme so that \nAndroid's LayoutInflater can resolve something initially:\n\n```xml\n\u003cstyle name=\"MyActivityTheme\" parent=\"Theme.AppCompat.Light\"\u003e\n  \u003citem name=\"my_custom_attr\"\u003e#000000\u003c/item\u003e\n\u003c/style\u003e\n```\n\nYou can use this attribute in your layouts:\n\n```xml\n\u003cTextView\n  android:layout_width=\"match_parent\"\n  android:layout_height=\"wrap_content\"\n  android:text=\"Hello, World!\"\n  android:textColor=\"?my_custom_attr\"\n  /\u003e\n```\n\nAnd you can assign dynamic values to it with Aesthetic:\n\n```kotlin\nAesthetic.config {\n\n   attributeRes(R.attr.your_attribute, R.color.blue)\n}\n```\n\nThe methods which end with `Res` take a color resource. Remove `Res` to \npass a literal (hardcoded) color integer.\n\n---\n\n# Advanced Views\n\nTo make Aesthetic a bit more plug-and-play, and to support views that \ncan't necessarily be color-themed from XML, additional options are \navailable for certain types of views.\n\n### Toolbars\n\nSpecial properties are provided for Toolbar icons (navigation icon, overflow icon, etc.) and the \ntitle and subtitle colors, so that they don't have to be paired with `textColorPrimary`, etc.\n\n```kotlin\nAesthetic.config {\n\n  // Defaults to black or white based on the darkness of ?colorPrimary.\n  toolbarIconColorRes(R.color.white)\n   \n  // Defaults to black or white based on the darkness of ?colorPrimary. \n  toolbarTitleColorRes(R.color.white)\n  // Defaults to a faded version of the title color.\n  toolbarSubtitleColorRes(R.color.light_gray)\n}\n```\n\nYou can override these (not including the icon color) at a per-layout basis as well:\n\n```xml\n\u003candroidx.appcompat.widget.Toolbar\n  ...\n  android:background=\"?some_color\"\n  app:titleTextColor=\"?some_color\"\n  app:subtitleTextColor=\"?some_color\"\n  /\u003e\n```\n\nIf you **do not** manually override background, the Toolbar will automatically \ndefault to the value of `?colorPrimary`.\n\n---\n\n### Snackbars\n\n\u003cimg src=\"https://raw.githubusercontent.com/afollestad/aesthetic/master/images/2.jpg\" width=\"400\" /\u003e\n\n```kotlin\nAesthetic.config {\n  // The color of the main text on a Snackbar\n  snackbarTextColorDefault()\n  snackbarTextColorRes(R.color.white)\n  \n  // The color of the action on a Snackbar, if there is one.\n  snackbarActionTextColorRes(R.color.blue)\n  \n  // The background color of Snackbar.\n  snackbarBackgroundColorDefault()\n  snackbarBackgroundColorRes(R.color.dark_gray)\n}\n```\n\n---\n\n### CardViews\n\n```kotlin\nAesthetic.config {\n  // The background of CardViews is different because of the \n  // rounding and elevation. This supports those elements.\n  colorCardViewBackgroundRes(R.color.white)\n}\n```\n\n---\n\n### TabLayouts\n\n*Note*: the color of text and icons in tab layouts will match that of Toolbars (using the \n`toolbarIconColor` and `toolbarTitleColor` attributes).\n\n```kotlin\nAesthetic.config {  \n  // The selected tab's underline will be the primary color.\n  tabLayoutIndicatorMode(ColorMode.PRIMARY)\n  // The selected tab's underline will be the accent color.\n  tabLayoutIndicatorMode(ColorMode.ACCENT)\n  \n  // The tab layout's background will be the primary color.\n  tabLayoutBackgroundMode(ColorMode.PRIMARY)\n  // The tab layout's background will be the accent color.\n  tabLayoutBackgroundMode(ColorMode.ACCENT)\n}\n```\n---\n\n### BottomNavigationViews\n\n\u003cimg src=\"https://raw.githubusercontent.com/afollestad/aesthetic/master/images/4.jpg\" width=\"400\" /\u003e\n\n```kotlin\nAesthetic.config {\n  // The tabs' background will be black or white based on the darkness \n  // of the overall theme.\n  bottomNavigationBackgroundMode(BottomNavBgMode.BLACK_WHITE_AUTO)\n  // The tabs' background will be the primary color.\n  bottomNavigationBackgroundMode(BottomNavBgMode.PRIMARY)\n  // The tabs' background will be the dark primary color.\n  bottomNavigationBackgroundMode(BottomNavBgMode.PRIMARY_DARK)\n  // The tabs' background will be the accent color.\n  bottomNavigationBackgroundMode(BottomNavBgMode.ACCENT)\n  // This library will not do any automatic background color theming of bottom nav views.\n  bottomNavigationBackgroundMode(BottomNavBgMode.NONE)\n  \n  // The selected tab's icon will be tinted with the primary color.\n  bottomNavigationIconTextMode(BottomNavIconTextMode.SELECTED_PRIMARY)\n  // The selected tab's icon will be tinted with the accent color. \n  bottomNavigationIconTextMode(BottomNavIconTextMode.SELECTED_ACCENT)\n  // The selected tab's icon will be tinted black or white based on \n  // the darkness of the overall theme.\n  bottomNavigationIconTextMode(BottomNavIconTextMode.BLACK_WHITE_AUTO)\n  // This library will not do any automatic icon/text theming of bottom nav views.\n  bottomNavigationIconTextMode(BottomNavBgMode.NONE)\n}\n```\n\n---\n\n### NavigationViews\n\n\u003cimg src=\"https://raw.githubusercontent.com/afollestad/aesthetic/master/images/3.jpg\" width=\"400\" /\u003e\n\n```kotlin\nAesthetic.config {  \n  // The selected drawer item will be tinted with the primary color.\n  navigationViewMode(NavigationViewMode.SELECTED_PRIMARY)\n  \n  // The selected drawer item will be tinted with the accent color. \n  navigationViewMode(NavigationViewMode.SELECTED_ACCENT)\n  \n  // This library will not apply any auto theming to NavigationViews. \n  navigationViewMode(NavigationViewMode.NONE)\n}\n```\n\n---\n\n### SwipeRefreshLayouts\n\n\u003cimg src=\"https://raw.githubusercontent.com/afollestad/aesthetic/master/images/6.jpg\" width=\"400\" /\u003e\n\n```kotlin\nAesthetic.config {\n\n  // You can pass one more more comma-separated colors. \n  // The colors that the refreshing indicator rotates through in a loop.\n  swipeRefreshLayoutColorsRes(R.color.red, R.color.blue)\n}\n```\n\n---\n\n# Custom Views and Manual Application\n\nAesthetic will not automatically theme most custom views, with some exceptions such as background\ncolor, text color, hint text color, an image view tint (these are handled without swapping view types).\n\nAesthetic makes it easy to subscribe to color changes so that you can manually apply colors to \nviews that need them.For an example, you can subscribe to pre-defined attributes, such as `colorPrimary()`:\n\n```kotlin\nval subscription = Aesthetic.get()\n  .colorPrimary()\n  .subscribe { color -\u003e\n      // Use color (an integer)\n  }\n      \n// Later, you should unsubscribe, e.g. when your Activity pauses or your View detaches from its Window\nsubscription.dispose()\n```\n\nIf you only need the latest value and no further updates:\n\n```kotlin\nAesthetic.get()\n  .colorPrimary()\n  .take(1)\n  .subscribe { color -\u003e\n      // Use color (an integer)\n  }\n```\n\nYou can do the same with custom attributes by switching `colorPrimary()` with \n`attribute(R.attr.your_attr)`.\n\n---\n\nYou can even setup an inflation delegate to auto-swap views at inflation time, like Aesthetic does\nwith a lot of stock/AndroidX views. This delegate is not called for views that Aesthetic already swaps internally. \n\n```kotlin\nclass MyInflationDelegate : InflationDelegate {\n\n  override fun createView(\n    context: Context,\n    attrs: AttributeSet?,\n    name: String,\n    viewId: Int\n  ): View? = when (name) {\n    \"com.somelibrary.CustomView\" -\u003e ThemedCustomView(context, attrs)\n    else -\u003e null\n  }\n}\n\nAesthetic.setInflationDelegate(MyInflationDelegate())\n```\n\n---\n\n# Ignoring Views\n\nYou can make this library ignore specific views from being themed with tags:\n\n```kotlin\n// Can also be set in you layout XML\nview.setTag(\":aesthetic_ignore\")\n\nview.setTag(R.id.aesthetic_ignore, \"anything other than null\")\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fafollestad%2Faesthetic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fafollestad%2Faesthetic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fafollestad%2Faesthetic/lists"}