- Managing your theme settings
- Темная тема android github
- Темная тема android github
- How to implement a dark theme on Android
- 1. Declare dependencies
- 2. Inherit from a DayNight theme
- 3. Use theme attributes for colors
- 4. Allow users to change the app’s theme
- 5. Run your app
- Sample
- GitHub показал темную тему вместе с потрясным видео
Managing your theme settings
You can manage how GitHub looks to you by setting a theme preference that either follows your system settings or always uses a light or dark mode.
For choice and flexibility in how and when you use GitHub, you can configure theme settings to change how GitHub looks to you. You can choose from themes that are light or dark, or you can configure GitHub to follow your system settings.
You may want to use a dark theme to reduce power consumption on certain devices, to reduce eye strain in low-light conditions, or because you prefer how the theme looks.
If you have low vision, you may benefit from a high contrast theme, with greater contrast between foreground and background elements. If you have colorblindness, you may benefit from our light and dark colorblind themes.
Note: The colorblind themes and light high contrast theme are currently in public beta. For more information on enabling features in public beta, see «Exploring early access releases with feature preview.»
In the upper-right corner of any page, click your profile photo, then click Settings.
In the user settings sidebar, click Appearance.
Under «Theme mode», select the drop-down menu, then click a theme preference.
Click the theme you’d like to use.
If you chose a single theme, click a theme.
If you chose to follow your system settings, click a day theme and a night theme.
If you would like to choose a theme which is currently in public beta, you will first need to enable it with feature preview. For more information, see «Exploring early access releases with feature preview.»
Note: You can also change your theme settings with the command palette. For more information, see «GitHub Command Palette».
Источник
Темная тема android github
A theme engine for Android.
Themes are immutable, possibilities are beautiful.
A powerful, dynamic, and fun theme engine. Named after Octopus Cyanea which is adept at camouflage and not only can change color frequently, but also can change the patterns on and texture of its skin.
Download the latest AAR or grab via Gradle:
Getting the project setup to use Cyanea is simple. First, initialize Cyanea in your Application class:
Also ensure that your MyApplication class is registered in your AndroidManifest.xml file:
Alternatively, you can use com.jaredrummler.cyanea.CyaneaApp as the Application class or have MyApplication class inherit from CyaneaApp (recommended).
You must declare your activity to extend any of the activity classes that start with ‘Cyanea’ (e.g., CyaneaAppCompatActivity, CyaneaFragmentActivity).
If you can’t extend your activity class, create a CyaneaDelegate and add the appropriate methods. See CyaneaAppCompatActivity.kt as an example.
Each activity must use a Theme.Cyanea theme (or decendant). You should declare the theme in the AndroidManifest :
The library provides core themes — one of which must be applied to each activity:
- Theme.Cyanea.Dark
- Theme.Cyanea.Dark.LightActionBar
- Theme.Cyanea.Dark.NoActionBar
- Theme.Cyanea.Light
- Theme.Cyanea.Light.DarkActionBar
- Theme.Cyanea.Light.NoActionBar
Set a default primary and accent color for the app in colors.xml :
Note: Do not set colorPrimary , colorPrimaryDark , colorAccent , etc. in the theme in styles.xml .
Cyanea adds preferences for choosing the primary, accent and background colors of the app. A theme-picker with 50+ pre-defined themes is also included in the library.
The following activites are added to launch the preferences and theme picker: CyaneaSettingsActivity , CyaneaThemePickerActivity .
To override and create your own pre-defined themes add the following file to your project: assets/themes/cyanea_themes.json . The file must be a JSON array with each theme as seen here.
Minimal JSON required for a pre-defined theme:
Use the following code to change the primary, accent or background colors of the app:
The methods which end with Resource take a color resource. Remove Resource to pass a literal (hardcoded) color integer. Unlike several other open source libraries, Cyanea can use any color you specify for primary, accent and background; you don’t need pre-defined styles.
You can get the current colors using cyanea.primary or using the default instance Cyanea.instance.primary .
Most views will automatically be themed using the library. To use the primary, accent, background, etc. colors use attributes in your layouts:
- ?colorPrimary
- ?colorPrimaryDark
- ?colorAccent
- ?backgroundColor
- ?backgroundColorDark
- ?backgroundColorLight
- ?menuIconColor
- ?subMenuIconColor
You can also use the primary, accent, background colors using @color/cyanea_primary_reference .
You can modify a view before it is laid out using a CyaneaViewProcessor . Simple let your Activity or Application implement CyaneaViewProcessor.Provider and add your processors to the array.
= TextView::class.java override fun process(view: TextView, attrs: AttributeSet?, cyanea: Cyanea) < view.text = "Hijacked!" >> ) > «>
You can inject custom attributes into layout files using CyaneaDecorator . The library ships with a FontDecorator which allows you to use app:cyaneaFont=»path/to/Font.ttf» in any view. The font will automatically be set on the view. To implement your own decorator, let your Activity or Application implement CyaneaDecorator.Provider and return an array of your custom decorators.
Please reference the FontDecorator as an example.
You can add an inflation delegate to hook into when views are created and create the views yourself.
Источник
Темная тема android github
Android Dark Theme in Action (Android深色模式实战)
从Android10(API 29)开始,在原有的主题适配的基础上,Google开始提供了Force Dark机制,在系统底层直接对颜色和图片进行转换处理,原生支持深色模式。到目前为止,我们从用户数据分析**50%**以上的用户已经使用上了Android10系统。深色模式可以节省电量、改善弱势及强光敏感用户的可视性,并能在环境亮度较暗的时候保护视力,更是夜间活跃用户的强烈需求。对深色模式的适配有利于提升用户口碑。
我们常见的需要设置的资源有 drawable 、 layout 、 mipmap 和 values 等,对于这些资源,我们可以用一些限定符来表示提供一些备用资源,例如 drawable-xhdpi 表示超密度屏幕使用的资源,或者 layout-land 表示横向状态使用的布局。
同样的深色模式可以使用资源的限定符 -night 来表示在深色模式中使用的资源。如下图所示:
使用了 -night 限定符的文件夹里面的资源我们称为 night 资源,没有使用 -night 限定符的资源我们称为 notnight 资源。
其中 drawable-night-xhdpi 可以放置对应超密度屏幕使用的深色模式的图片, values-night 可以声明对应深色模式使用的色值和主题。
所有的资源限定符定义以及添加的顺序(例如 -night 必须在 -xhdpi 之前)可查看应用资源概览中的配置限定符名称表。
Application层通过 AppCompatDelegate.setDefaultNightMode() 设置深色模式。
当深色模式改变时,Activity会重建,如果不希望Activity重建,可以在 AndroidManifest.xml 中对对应的Activity设置 android:configChanges=»uiMode» ,不过设置之后页面的颜色改变需要Activity在中通过监听 onConfigurationChanged 来动态改变。
Tips:注意,深色模式变化会导致Activity重建, AppCompatDelegate.setDefaultNightMode(int) 方法仅对继承自AppCompactActivity的页面有效。
将Application和Activity的主题修改为集成自 Theme.AppCompat.DayNight 或者 Theme.MaterialComponents.DayNight ,就可以对于大部分的控件得到较好的深色模式支持。我们看下DayNight主题的定义:
res/values/values.xml
res/values-night/themes.xml
- colorPrimary:主要品牌颜色,一般用于ActionBar背景
- colorPrimaryDark:默认用于顶部状态栏和底部导航栏
- colorPrimaryVariant:主要品牌颜色的可选颜色
- colorSecondary:第二品牌颜色
- colorSecondaryVariant:第二品牌颜色的可选颜色
- colorPrimarySurface:对应Light主题指向colorPrimary,Dark主题指向colorSurface
- colorOn[Primary, Secondary, Surface . ],在Primary等这些背景的上面内容的颜色,例如ActioBar上面的文字颜色
- colorAccent:默认设置给colorControlActivated,一般是主要品牌颜色的明亮版本补充
- colorControlNormal:图标和控制项的正常状态颜色
- colorControlActivated:图标和控制项的选中颜色(例如Checked或者Switcher)
- colorControlHighlight:点击高亮效果(ripple或者selector)
- colorButtonNormal:按钮默认状态颜色
- colorSurface:cards, sheets, menus等控件的背景颜色
- colorBackground:页面的背景颜色
- colorError:展示错误的颜色
- textColorPrimary:主要文字颜色
- textColorSecondary:可选文字颜色
Tips: 当某个属性同时可以通过 ?attr/xxx 或者 ?android:attr/xxx 获取时,最好使用 ?attr/xxx ,因为 ?android:attr/xxx 是通过系统获取,而 ?attr/xxx 是通过静态库类似于AppCompat 或者 Material Design Component引入的。使用非系统版本的属性可以提高平台通用性。
如果需要自定义主题颜色,我们可以对颜色分别定义 notnight 和 night 两份,放在 values 以及 values-night 资源文件夹中,并在自定义主题时,传入给对应的颜色属性。例如:
Источник
How to implement a dark theme on Android
Android 10 adds a system-wide dark theme, which preserves battery power for devices with OLED screens, reduces eye strain, and facilitates use in low-light environments.
These guidelines will show you how to implement a dark theme on Android, even on earlier versions of the platform.
1. Declare dependencies
Add the following dependencies to your project:
2. Inherit from a DayNight theme
The easiest way to support a dark theme is to inherit from a DayNight theme such as Theme.AppCompat.DayNight .
Basically, a DayNight theme is composed of a Light theme in the values directory and a Dark theme in the values-night directory.
For example, declare a Theme.MaterialComponents.DayNight.NoActionBar.Bridge :
And then, declare your AppTheme :
3. Use theme attributes for colors
When writing your layouts, use theme attributes or night-qualified resources instead of hard-coded colors to ensure that they display suitable colors in a Light theme and in a Dark theme.
For example, when you use a FloatingActionButton , the default backgroundTint is ?attr/colorAccent so the tint should be ?android:attr/textColorPrimaryInverse to ensure that the contrast ratio between the icon and its background is eligible:
In a Light theme, it will display a #ffffffff icon on a #ff009688 background.
In a Dark theme, it will display a #de000000 icon on a #ff80cbc4 background.
4. Allow users to change the app’s theme
Your app should let the user switch between themes, which map directly to one of the following modes:
Use AppCompatDelegate.setDefaultNightMode to switch the theme for all components in your app. Please note that it is not saved when the app is killed so you should use Settings to save the user’s choice.
For example, use the following code in your Activity to change the night mode:
And then, use the following code in your Application to restore the night mode:
5. Run your app
That’s it, you are ready to run your app and enjoy a dark theme!
Sample
For a complete example, check out my sample on GitHub.
Источник
GitHub показал темную тему вместе с потрясным видео
GitHub объявил, что долгожданная темная тема, наконец, готова, ознаменовав анонс характерным крутейшим (но не без иронии) видео, которое лучше сто раз увидеть, чем сто раз услышать.
Эта новость была обнародована сегодня в рамках GitHub Universe, ежегодной конференции разработчиков, которая, как и многие другие, в этом году из-за пандемии коронавируса переместилась в онлайн. Первые слухи о темном режиме на самом деле ходили еще с Universe 2018, затем снова как «не за горами» в 2019 году. Сегодня, наконец, дождались.
Переключение между двумя режимами осуществляется в новом подменю настроек «Appearance». Оттуда вы можете выбрать режимы «Light», «Dark» или «Default to system» (системную тему):
Теперь давайте взглянем на две одинаковые страницы: одна – в старом добром светлом режиме, а другая – в царстве тьмы.
Вот еще одно изображение. Показывает, как будут выглядеть ваши проекты, пока вы их пишете:
Хотя многие пользователи предпочитают темный режим (или, как выражается GitHub, желая «почувствовать себя Мистером Роботом»), у него есть и другие преимущества, как для пользователя, поскольку снижается утомляемость глаз, так и для устройства, ведь темный режим расходует меньше энергии. Какой бы ни была причина использовать темный режим у GitHub, вы точно не одиноки: вместе с вами многие разработчики будут рады этой новости. Да наступит тьма!
Другие объявления первого дня включают в себя запуск автоматического объединения для пулл-реквестов, области «Discussions» для разработчиков, где они могут объединиться в коллективный разум, а также ряд улучшений функции «Actions», которая дебютировала ранее в этом году. Также было объявлено о запуске Github Enterprise Server 3.0. Github Universe продолжится завтра и в пятницу с более чем 70 сессиями, охватывающими весь спектр тем, связанных с разработкой программного обеспечения с открытым исходным кодом и не только.
Источник