The Android Arsenal – Static Analysis Tools


A set of lint rules that keep us from using HEX values ​​or direct color resources instead of attributes when we create our layouts either via XML or programmatically.
How to Update Your Knowledge of Theme Colors: Material Guidelines.

installation

AndroidStyling LintRules is sold through Maven Central, Jcenter and Jitpack.

implementation 'com.github.guilhe:styling-lint:${LATEST_VERSION}'

use

Well that’s easy. Your styles and layouts should always use attributes to get the color out of the appropriate theme.
Hence in situations like:

<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:textColor="@color/black"/>

You will get a warning asking you to change it:

These rules don’t apply to layouts only:

getColor(R.color.colorPrimary)

You will also get a warning asking you to change these:

In code situations, getting a color from a theme isn’t that trivial, and it involves a bit of code on the boiler plate.
For this reason, ResourcesProvider-ktx can come into hand. It is an auxiliary class for providing resources and has “topic support”:

.setBackgroundColor(resourcesProvider.colorRes(R.attr.colorPrimary, R.style.App_Style_A)

Bugs and feedback

For bugs, questions, and discussions, please use the Github issues.

LICENSE

Copyright (c) GuilhE until 2020

Licensed under the Apache License, Version 2.0 (the “License”); You may only use this file in accordance with the license. You can get a copy of the license at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by law or agreed in writing, the software distributed under the license is distributed “AS IS” without any warranty or condition, express or implied, of any kind. In the license, you can find the specific language for permissions and restrictions under the license.

Recent Articles

Related Stories

Leave A Reply

Please enter your comment!
Please enter your name here

Stay on op - Ge the daily news in your inbox