在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):androidessence/MaterialDesignSpecs开源软件地址(OpenSource Url):https://github.com/androidessence/MaterialDesignSpecs开源编程语言(OpenSource Language):Kotlin 98.4%开源软件介绍(OpenSource Introduction):Material Design Specs LibraryThis library provides an easy and quick way to access the entire material design color palette and elevation values, along with some neat helper methods like random access to material design colors. UsageTo have access to the library, add the dependency to your build.gradle: implementation 'com.androidessence:materialdesignspecs:2.0.1' At the time of publication, the library has not yet been linked to JCenter, so you will also have to add the link to our Maven repository as well: repositories {
maven {
url "http://dl.bintray.com/androidessence/maven"
}
} Now, you'll be able to access the full color pallete from material design, either by XML, or programatically.
<!-- You can use it in any view or other XML resources -->
<!-- Access the resources by using @color/ or @dimen/ -->
<View
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/mds_red_500"
android:elevation="@dimen/mds_elevation_card_resting"/>
// Access it through the android R file. Like the examples below.
R.color.mds_red_500
R.color.mds_blue_700
R.color.mds_pink_A100
R.color.mds_indigo_200
// Elevations
R.dimen.mds_elevation_card_resting
R.dimen.mds_elevation_dialog
R.dimen.mds_elevation_navigation_view
R.dimen.mds_elevation_menu You'll also have access to some static helper methods like: getColorsByName(String colorName) // Returns a List<Integer> of colors with the given name.
// The methods below returns an Integer to use along your code.
getRandomColor()
getRandomNonAccentColor()
getRandomColorByLevel(String colorLevel)
getRandomColorByName(String colorName)
getRandomColorNonRepeating()
// And a few more! To specify a color name or level, use the available static strings such as: MaterialPalettes.RED
MaterialPalettes.LEVEL_500 Please be aware that the Integer returned by the methods above is the Integer of the resource identifier, not the color itself. So, in order to give a TextView a random text color, it would be done like this: Integer randomColor = MaterialPalettes.getRandomColor();
myTextView.setTextColor(getResources().getColor(randomColor)); ColorPickerMDS also supplies a built in ColorPicker dialog you can use to allow users to pick a color. There's both a circle and a square color adapter you can use, and also a base one you can implement to make your own. Supply an adapter and a list of colors for the picker, as well as implement an try {
ColorDialog colorDialog = ColorDialog.newInstance(MaterialPalettes.getColorsByLevel(MaterialPalettes.LEVEL_500), selectedPos);
colorDialog.setOnColorSelectedListener(this);
colorDialog.setAdapter(new CircleColorAdapter(this));
colorDialog.setLayoutManager(new GridLayoutManager(MainActivity.this, GRID_COUNT));
colorDialog.show(getSupportFragmentManager(), CIRCLE_COLOR_PICKER_TAG);
} catch (IllegalAccessException iae) {
Log.e(MainActivity.class.getSimpleName(), iae.getMessage(), iae);
} Note that depending on orientation or screen size, you may want to consider how many columns you add to the GridLayoutManager. For example, 5 columns on a Nexus 6P begin to overlap and don't look god together. SampleTo see the library in action, this is the output of getting all 500 level colors and displaying them in individual TextViews: Here is an example of the ColorPicker in action: ColorsHere's the list of the colors names. Change "X" to the color level, like "50" or "A100".
The color levels can be:
And the accent ones are:
Example of a color: Reminder: brown, grey, and bluegrey don't have accent colors. We highly recommend you use this library for the mds_white and mds_black colors as well, as some OEM's change the The full color palettes as well as some more information on how to use them can be found in Google's Material Design Specifications. Elevation valuesTo know which elevation value to use, please refer to the material design specs. And with that you're all set. Go make some awesome apps with our lib :) Credits & ContactMaterial Design Specs Lib was created with <3 by: With special thanks to Eric Cugota for helping us get this into Bintray and make it available for you. And it's released under Android Essence blog. If you contribute to this library, please add yourself to this section when you submit your pull request. LicenseMaterial Design Specs Lib is available under the MIT License. When you use it, don't forget to mention us ;) Happy coding! |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论