国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android 設置主題實現點擊波紋效果的示例

2019-10-22 18:23:19
字體:
來源:轉載
供稿:網友

開頭先說說大家都知道的Material Design。

Material Design:

Material Design是Google推出的一個全新的設計語言,它的特點就是擬物扁平化。

Material Design包含了很多內容,我大致把它分為四部分:

  1. 主題和布局
  2. 視圖和陰影
  3. UI控件
  4. 動畫

Material Theme

使用Material主題:

Material主題只能應用在Android L版本。

應用Material主題很簡單,只需要修改res/values/styles.xml文件,使其繼承android/209620.html">android/273229.html">android:Theme.Material。如下:

<!-- res/values/styles.xml --> <resources>  <!-- your app's theme inherits from the Material theme -->  <style name="AppTheme" parent="android:Theme.Material">   <!-- theme customizations -->  </style> </resources> 

或者在AndroidManifest.xml中直接設置主題:

android:theme="@android:style/Theme.Material.Light" 

在最新的5.0中,google似乎不推薦使用Material Design主題了,而是由AppCompat代替。

<resources>    <!-- Base application theme. -->   <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">     <!-- Customize your theme here. -->     <item name="colorPrimary">@color/colorPrimary</item>     <item name="colorPrimaryDark">@color/colorPrimaryDark</item>     <item name="colorAccent">@color/colorAccent</item>   </style>  </resources> 

自定義狀態條和導航條:

material還允許你輕松的自定義狀態條和導航條的顏色。

可以使用如下屬性(參考下方圖片):

android:statusBarColor,Window.setStatusBarColor

android,水波紋點擊,點擊波紋效果

兼容性:

由于Material Theme只可以在Android L Developer Preview中使用。

所以在低版本使用的話就需要為其另設一套主題:

在老版本使用一套主題 res/values/styles.xml,在新版本使用Material主題res/values-v21/styles.xml.

系統自帶點擊事件的控件一般都具有默認的波紋效果,直接使用即可:

<RelativeLayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         >          <Button           android:id="@+id/myBtn"           android:layout_width="match_parent"           android:layout_height="wrap_content"           android:drawablePadding="10dp"           android:gravity="center_vertical"           android:paddingBottom="15dip"           android:paddingLeft="15dip"           android:paddingRight="25dip"           android:paddingTop="15dip"           android:text="Click"           android:textColor="@color/common_black_text"           android:textSize="16sp" />       </RelativeLayout> 

怎么為view添加點擊波紋效果呢,先了解下面的東西。

觸摸反饋:

在Android L5.0中加入了觸摸反饋動畫。

其中最明顯,最具代表性的就是波紋動畫,比如當點擊按鈕時會從點擊的位置產生類似于波紋的擴散效果。

波紋效果(Ripple):

當你使用了Material主題后,波紋動畫會自動應用在所有的控件上,我們當然可以來設置其屬性來調整到我們需要的效果。

可以通過如下代碼設置波紋的背景:

android:background="?android:attr/selectableItemBackground"波紋有邊界android:background="?android:attr/selectableItemBackgroundBorderless"波紋超出邊界

使用效果如下:

B1是不設任何背景的按鈕

B2設置了?android:attr/selectableItemBackground

B3設置了?android:attr/selectableItemBackgroundBorderless

android,水波紋點擊,點擊波紋效果

設置顏色

我們也可以通過設置xml屬性來調節動畫顏色,從而可以適應不同的主題:

android:colorControlHighlight:設置波紋顏色

android:colorAccent:設置checkbox等控件的選中顏色

比如下面這個比較粉嫩的主題,就需要修改動畫顏色來匹配(上面已經有介紹):

android,水波紋點擊,點擊波紋效果

為view添加波紋效果:

<RelativeLayout         android:id="@+id/user_info_layout"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:clickable="true"         android:background="?android:attr/selectableItemBackground"         android:layout_marginTop="10dp"         android:paddingBottom="15dip"         android:paddingTop="15dip">          <TextView           android:id="@+id/user_info_text"           android:layout_width="wrap_content"           android:layout_height="wrap_content"           android:drawablePadding="10dp"           android:gravity="center_vertical"           android:paddingLeft="15dip"           android:paddingRight="25dip"           android:text="我的資料"           android:textSize="16sp" />          <ImageView           android:layout_width="wrap_content"           android:layout_height="wrap_content"           android:layout_alignParentRight="true"           android:layout_centerInParent="true"           android:contentDescription="@null"           android:paddingRight="15dip"            />       </RelativeLayout> 

為Textview添加波紋效果:

<LinearLayout         android:layout_width="match_parent"         android:layout_height="68dp"         android:weightSum="4"         android:gravity="center_vertical">          <TextView           android:id="@+id/user_unpaid"           android:layout_width="0dp"           android:layout_height="wrap_content"           android:background="?android:attr/selectableItemBackgroundBorderless"           android:drawableTop="@mipmap/ic_user_paid"           android:drawablePadding="5dp"           android:gravity="center"           android:layout_weight="1"           android:text="待付款"           android:textSize="12sp"           android:clickable="true"/>         <TextView           android:id="@+id/user_paid"           android:layout_width="0dp"           android:layout_height="wrap_content"           android:background="?android:attr/selectableItemBackgroundBorderless"           android:drawableTop="@mipmap/ic_user_paid"           android:drawablePadding="5dp"           android:layout_weight="1"           android:gravity="center"           android:text="待發貨"           android:textColor="@color/common_black_text"           android:textSize="12sp"           android:clickable="true"/>         <TextView           android:id="@+id/user_unreceived"           android:layout_width="0dp"           android:layout_height="wrap_content"           android:background="?android:attr/selectableItemBackgroundBorderless"           android:drawableTop="@mipmap/ic_user_paid"           android:drawablePadding="5dp"           android:gravity="center"           android:layout_weight="1"           android:text="待收貨"           android:textColor="@color/common_black_text"           android:textSize="12sp"           android:clickable="true"/>         <TextView           android:id="@+id/user_completed"           android:layout_width="0dp"           android:layout_height="wrap_content"           android:background="?android:attr/selectableItemBackgroundBorderless"           android:drawableTop="@mipmap/ic_user_paid"           android:drawablePadding="5dp"           android:gravity="center"           android:layout_weight="1"           android:text="已完成"           android:textSize="12sp"           android:clickable="true"/>        </LinearLayout> 

這樣就可以實現波紋效果啦!

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 镇宁| 双峰县| 双城市| 治县。| 郁南县| 河北区| 静宁县| 兴化市| 嘉善县| 屏东市| 师宗县| 琼海市| 繁峙县| 漾濞| 泾阳县| 田林县| 静乐县| 六安市| 中方县| 德庆县| 安平县| 淳安县| 古浪县| 富宁县| 阿克陶县| 巫溪县| 新源县| 遵化市| 临西县| 淳化县| 邹城市| 枝江市| 宝丰县| 平山县| 福海县| 霍州市| 莫力| 普兰县| 同仁县| 手游| 昌图县|