網站首頁 編程語言 正文
效果圖
第三方庫支持
Github:https://github.com/fornewid/neumorphism
代碼示例
將介紹第三方庫引入和xml布局
引入第三方庫
引入jitpack.io,添加到工程級build.gradle,若是Kotlin項目工程則在 settings.gradle 中引入
allprojects { repositories { maven { url "https://jitpack.io" } } }
在項目中引入
//新擬物化風格 implementation 'com.github.fornewid:neumorphism:0.3.2'
黑暗模式布局
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#1A1A1A" android:gravity="center_horizontal" android:orientation="vertical" tools:context=".activity.TestActivity"> <soup.neumorphism.NeumorphCardView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="50dp" app:neumorph_shadowColorDark="#0E0E0E" app:neumorph_shadowColorLight="#202020"> <LinearLayout android:layout_width="316dp" android:layout_height="200dp" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="20dp" android:layout_marginTop="10dp" android:text="程序員銀行" android:textColor="#2E2E2E" android:textSize="18sp" /> <soup.neumorphism.NeumorphTextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="20dp" android:layout_marginTop="100dp" android:text="898989 1234567890 " android:textColor="#1A1A1A" android:textSize="26sp" android:textStyle="bold" app:neumorph_shadowColorDark="#0E0E0E" app:neumorph_shadowColorLight="#202020" /> </LinearLayout> </soup.neumorphism.NeumorphCardView> <soup.neumorphism.NeumorphTextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginVertical="20dp" android:text="This is Text " android:textColor="#1A1A1A" android:textSize="26sp" android:textStyle="bold" app:neumorph_shadowColorDark="#0E0E0E" app:neumorph_shadowColorLight="#202020" /> <soup.neumorphism.NeumorphButton android:id="@+id/btn1" android:layout_width="150dp" android:layout_height="65dp" android:gravity="center" android:text="靈魂按鈕" android:textColor="#5E5E5E" app:neumorph_shadowColorDark="#0E0E0E" app:neumorph_shadowColorLight="#202020" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:orientation="horizontal"> <soup.neumorphism.NeumorphCardView android:layout_width="100dp" android:layout_height="100dp" app:neumorph_shadowColorDark="#0E0E0E" app:neumorph_shadowColorLight="#202020" /> <soup.neumorphism.NeumorphCardView android:layout_width="100dp" android:layout_height="100dp" app:neumorph_shadowColorDark="#0E0E0E" app:neumorph_shadowColorLight="#202020" app:neumorph_shapeType="basin" app:neumorph_strokeColor="#1A1A1A" app:neumorph_strokeWidth="8dp" /> <soup.neumorphism.NeumorphCardView android:layout_width="100dp" android:layout_height="100dp" app:neumorph_shadowColorDark="#0E0E0E" app:neumorph_shadowColorLight="#202020" app:neumorph_shapeType="pressed" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:orientation="horizontal"> <soup.neumorphism.NeumorphFloatingActionButton android:layout_width="100dp" android:layout_height="100dp" app:neumorph_shadowColorDark="#0E0E0E" app:neumorph_shadowColorLight="#202020" /> <soup.neumorphism.NeumorphImageView android:layout_width="100dp" android:layout_height="100dp" android:layout_marginHorizontal="15dp" android:padding="25dp" android:scrollbarSize="15sp" android:src="@mipmap/face" app:neumorph_shadowColorDark="#0E0E0E" app:neumorph_shadowColorLight="#202020" /> <soup.neumorphism.NeumorphFloatingActionButton android:layout_width="100dp" android:layout_height="100dp" app:neumorph_shadowColorDark="#0E0E0E" app:neumorph_shadowColorLight="#202020" app:neumorph_shapeType="pressed" /> </LinearLayout> </LinearLayout>
明亮風格
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#F3F3F3" android:gravity="center_horizontal" android:orientation="vertical" tools:context=".activity.TestActivity"> <soup.neumorphism.NeumorphCardView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="50dp"> <LinearLayout android:layout_width="316dp" android:layout_height="200dp" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="20dp" android:layout_marginTop="10dp" android:text="程序員銀行" android:textColor="#999999" android:textSize="18sp" /> <soup.neumorphism.NeumorphTextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="20dp" android:layout_marginTop="100dp" android:text="898989 1234567890 " android:textColor="#F3F3F3" android:textSize="26sp" android:textStyle="bold" app:neumorph_shapeType="pressed" /> </LinearLayout> </soup.neumorphism.NeumorphCardView> <soup.neumorphism.NeumorphTextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginVertical="20dp" android:text="This is Text " android:textColor="#F3F3F3" android:textSize="26sp" android:textStyle="bold" /> <soup.neumorphism.NeumorphButton android:id="@+id/btn1" android:layout_width="150dp" android:layout_height="65dp" android:gravity="center" android:text="靈魂按鈕" android:textColor="#999999" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:orientation="horizontal"> <soup.neumorphism.NeumorphCardView android:layout_width="100dp" android:layout_height="100dp" /> <soup.neumorphism.NeumorphCardView android:layout_width="100dp" android:layout_height="100dp" app:neumorph_shapeType="basin" app:neumorph_strokeColor="#F3F3F3" app:neumorph_strokeWidth="8dp" /> <soup.neumorphism.NeumorphCardView android:layout_width="100dp" android:layout_height="100dp" app:neumorph_shapeType="pressed" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:orientation="horizontal"> <soup.neumorphism.NeumorphFloatingActionButton android:layout_width="100dp" android:layout_height="100dp" /> <soup.neumorphism.NeumorphImageView android:layout_width="100dp" android:layout_height="100dp" android:layout_marginHorizontal="15dp" android:padding="25dp" android:scrollbarSize="15sp" android:src="@mipmap/face" /> <soup.neumorphism.NeumorphFloatingActionButton android:layout_width="100dp" android:layout_height="100dp" app:neumorph_shapeType="pressed" /> </LinearLayout> </LinearLayout>
文檔說明(案例)
<soup.neumorphism.NeumorphCardView <!--預定義樣式--> style="@style/Widget.Neumorph.CardView" <!--設置陰影高度和顏色--> app:neumorph_shadowElevation="6dp" app:neumorph_shadowColorLight="@color/solid_light_color" app:neumorph_shadowColorDark="@color/solid_dark_color" <!--設置光源--> app:neumorph_lightSource="leftTop|leftBottom|rightTop|rightBottom" <!--設置形狀類型和角尺寸--> app:neumorph_shapeType="{flat|pressed|basin}" app:neumorph_shapeAppearance="@style/CustomShapeAppearance" <!--設置背景或描邊--> app:neumorph_backgroundColor="@color/background_color" app:neumorph_strokeColor="@color/stroke_color" app:neumorph_strokeWidth="@dimen/stroke_width" <!--使用插圖來避免剪裁陰影。 (默認為12dp)--> app:neumorph_inset="12dp" app:neumorph_insetStart="12dp" app:neumorph_insetEnd="12dp" app:neumorph_insetTop="12dp" app:neumorph_insetBottom="12dp" <!--使用填充,默認為12db--> android:padding="12dp"> <!--在這里可以直接包裹子布局--> </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>
總結
原文鏈接:https://blog.csdn.net/qq_40881680/article/details/122980254
相關推薦
- 2023-07-22 macos設置環境變量path詳解
- 2022-08-16 Hive?HQL支持2種查詢語句風格_數據庫其它
- 2022-04-16 pycharm三個有引號不能自動生成函數注釋的問題_python
- 2022-08-23 C++?primer超詳細講解泛型算法_C 語言
- 2022-12-09 React內部實現cache方法示例詳解_React
- 2022-07-20 使用numpy.ndarray添加元素_python
- 2022-11-25 Linux?apache實現https的配置方法_Linux
- 2022-04-01 ctr鏡像導入報錯ctr: content digest sha256:xxxxxx not fou
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支