Android實(shí)現(xiàn)Neumorphism?UI控件
效果圖
第三方庫支持
Github:https://github.com/fornewid/neumorphism
代碼示例
將介紹第三方庫引入和xml布局
引入第三方庫
引入jitpack.io,添加到工程級(jí)build.gradle,若是Kotlin項(xiàng)目工程則在 settings.gradle 中引入
allprojects { repositories { maven { url "https://jitpack.io" } } }
在項(xiàng)目中引入
//新擬物化風(fēng)格 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>
明亮風(fēng)格
<?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 <!--預(yù)定義樣式--> style="@style/Widget.Neumorph.CardView" <!--設(shè)置陰影高度和顏色--> app:neumorph_shadowElevation="6dp" app:neumorph_shadowColorLight="@color/solid_light_color" app:neumorph_shadowColorDark="@color/solid_dark_color" <!--設(shè)置光源--> app:neumorph_lightSource="leftTop|leftBottom|rightTop|rightBottom" <!--設(shè)置形狀類型和角尺寸--> app:neumorph_shapeType="{flat|pressed|basin}" app:neumorph_shapeAppearance="@style/CustomShapeAppearance" <!--設(shè)置背景或描邊--> app:neumorph_backgroundColor="@color/background_color" app:neumorph_strokeColor="@color/stroke_color" app:neumorph_strokeWidth="@dimen/stroke_width" <!--使用插圖來避免剪裁陰影。 (默認(rèn)為12dp)--> app:neumorph_inset="12dp" app:neumorph_insetStart="12dp" app:neumorph_insetEnd="12dp" app:neumorph_insetTop="12dp" app:neumorph_insetBottom="12dp" <!--使用填充,默認(rèn)為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>
總結(jié)
到此這篇關(guān)于Android實(shí)現(xiàn)Neumorphism UI控件的文章就介紹到這了,更多相關(guān)Android Neumorphism UI控件內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Android ApplicationContext接口深入分析
ApplicationContext是Spring應(yīng)用程序中的中央接口,由于繼承了多個(gè)組件,使得ApplicationContext擁有了許多Spring的核心功能,如獲取bean組件,注冊(cè)監(jiān)聽事件,加載資源文件等2022-11-11android電源信息查看(電量、溫度、電壓)實(shí)例代碼
這篇文章主要介紹了android電源信息查看方法,以實(shí)例形式較為詳細(xì)的分析了Android實(shí)現(xiàn)電源電量、電壓、溫度等信息查看的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-10-10android 使用 IJKPlayer 播放視頻流的實(shí)現(xiàn)代碼
這篇文章主要介紹了android 使用 IJKPlayer 播放視頻流,這需要借助 IAndroidIO 這個(gè)接口,也可以用于播放本地文件,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-11-11基于android studio的layout的xml文件的創(chuàng)建方式
這篇文章主要介紹了基于android studio的layout的xml文件的創(chuàng)建方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-03-03全面解析Android應(yīng)用開發(fā)中Activity類的用法
這篇文章主要介紹了Android應(yīng)用開發(fā)中Activity類的用法,包括Activity間的數(shù)據(jù)傳遞以及Activity的創(chuàng)建方式等,需要的朋友可以參考下2016-02-02Android中webview與JS交互、互調(diào)方法實(shí)例詳解
這篇文章主要介紹了Android中webview與JS交互、互調(diào)方法實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下2017-03-03Android使用MediaRecorder類進(jìn)行錄制視頻
這篇文章主要介紹了Android使用MediaRecorder類進(jìn)行錄制視頻的相關(guān)資料,需要的朋友可以參考下2015-10-10如何在Android中實(shí)現(xiàn)漸顯按鈕的左右滑動(dòng)效果
本篇文章是對(duì)在Android中實(shí)現(xiàn)漸顯按鈕的左右滑動(dòng)效果進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06