前言
本文转自github,只是进行了图片的处理和部分翻译,已获作者授权
截至首次发文前找到的原作者的文章地址-May,17,2020若找到本文章更新的时间节点,请私信我更新。
原作者github地址
文末附源码下载地址,免费。
Android上的拟态化UI
This is the experimental codes to build Neumorphism designs in Android.
Not a library. Just sample project now(目前只是示例项目).
Preview
Light | Dark
添加依赖
在项目级 build.gradle
添加以下依赖:
allprojects {
repositories {
maven { url "https://jitpack.io" }
}
}
然后, 在 build.gradle
中添加以下依赖
dependencies {
//截至首次发文前latest_version为0.3.0
implementation 'com.github.fornewid:neumorphism:{latest_version}'
}
Features
- 为组件绘制阴影实现新拟态化效果。
支持以下组件:- ViewGroup: CardView
- View: Button, FloatingActionButton, ImageView
- 在Text上绘制阴影来实现TextView的新拟态化。
如果您需要更多功能或要修复错误,请单击 new issue并报告给我!
示例
<soup.neumorphism.NeumorphCardView
// 预定义样式
style="@style/Widget.Neumorph.CardView"
// 设置elevation和color
app:neumorph_shadowElevation="6dp"
app:neumorph_shadowColorLight="@color/solid_light_color"
app:neumorph_shadowColorDark="@color/solid_dark_color"
// 设置光源 lightSource
app:neumorph_lightSource="leftTop|leftBottom|rightTop|rightBottom"
// 设置Shape类型和corner size
app:neumorph_shapeType="{flat|pressed|basin}"
app:neumorph_shapeAppearance="@style/CustomShapeAppearance"
// 设置 background 或 stroke
app:neumorph_backgroundColor="@color/background_color"
app:neumorph_strokeColor="@color/stroke_color"
app:neumorph_strokeWidth="@dimen/stroke_width"
使用插图以避免修剪阴影
// 使用 inset 以避免阴影被裁剪. (default=12dp)
app:neumorph_inset="12dp"
app:neumorph_insetStart="12dp"
app:neumorph_insetEnd="12dp"
app:neumorph_insetTop="12dp"
app:neumorph_insetBottom="12dp"
// Use a padding. (default=12dp)
android:padding="12dp">
<!-- NeumorphCardView extends FrameLayout. So you can wrap childrens like this. -->
<ConstraintLayout />
</soup.neumorphism.NeumorphCardView>
<style name="CustomShapeAppearance">
<item name="neumorph_cornerFamily">{rounded|oval}</item>
<item name="neumorph_cornerSize">32dp</item>
<!-- Or if wants different radii depending on the corner. -->
<item name="neumorph_cornerSizeTopLeft">16dp</item>
<item name="neumorph_cornerSizeTopRight">16dp</item>
<item name="neumorph_cornerSizeBottomLeft">16dp</item>
<item name="neumorph_cornerSizeBottomRight">16dp</item>
</style>
LEFT_TOP | LEFT_BOTTOM | RIGHT_TOP | RIGHT_BOTTOM |
---|---|---|---|
FLAT | PRESSED | BASIN |
---|---|---|
License
Copyright 2020 SOUP
Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this
file to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.