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

首頁 > 系統 > Android > 正文

Android5.0新控件實例詳解

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

谷歌在推出Android5.0的同時推出了一些新控件,Android5.0中最常用的新控件有下面5種。

android,5.0新控件,新控件

1. CardView(卡片視圖)

CardView顧名思義是卡片視圖,它繼承FrameLayout。它是一個帶圓角的背景和陰影FrameLayout。CardView被包裝為一種布局,并且經常在ListView和RecyclerView的Item布局中,作為容器使用。
CardView的使用非常簡單:

<android.support.v7.widget.CardView    android:layout_width="match_parent"    android:layout_height="60dp">    <Button      android:id="@+id/ripple_button"      android:layout_width="match_parent"      android:layout_height="50dp"      android:layout_gravity="center"      android:layout_margin="5dp"      android:background="@drawable/ripple"      android:gravity="center"      android:text="我在一個CardView里面" />  </android.support.v7.widget.CardView>

android,5.0新控件,新控件

2. Patelle(調色板)

Patelle是一個輔助類,它的作用是從圖片中獲取突出的顏色。
它可以提取下面幾種特性的突出顏色:

- Vibrant(充滿活力的)
- Vibrant Dark(充滿活力,黑暗的)
- Vibrant Light(充滿活力的,明亮的)
- Muted(柔和的)
- Muted Dark(柔和的,黑暗的)
- Muted Light(柔和的,明亮的)

Patelle的使用也非常簡單:

 // 獲取應用程序圖標的Bitmap bitmap= BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher); // 通過bitmap生成調色板palettePalette palette=Palette.from(bitmap).generate(); // 獲取palette充滿活力色顏色 int vibrantColor=palette.getVibrantColor(Color.WHITE); 

3. Toolbar(工具欄)

Toolbar顧名思義是工具欄,作為ActionBar的替代品出現,谷歌推薦使用Toolbar替代ActionBar。
Toolbar可以放置在任何地方,不像ActionBar一樣只能放置在固定的位置。
Toolbar支持比ActionBar更集中的特征。
Toolbar可能包含以下可選元素的組合:
- 導航按鈕
- 品牌的Logo圖像
- 標題和子標題
- 一個或多個自定義視圖

this.toolbar = (Toolbar) findViewById(R.id.toolbar);this.recyclerview = (RecyclerView) findViewById(R.id.recycler_view);this.ripplebutton = (Button) findViewById(R.id.ripple_button);this.button = (Button) findViewById(R.id.button);// 設置Logotoolbar.setLogo(R.mipmap.ic_launcher);// 設置標題toolbar.setTitle("Android5.0");// 設置子標題toolbar.setSubtitle("新控件");//設置ActionBar,之后就可以獲取ActionBar并進行操作,操作的結果就會反應在toolbar上面setActionBar(toolbar);//設置了返回箭頭,,相當于設置了toolbar的導航按鈕getActionBar().setDisplayHomeAsUpEnabled(true);

android,5.0新控件,新控件

4. RippleDrawable(波紋圖)

RippleDrawable顧名思義是波紋圖,只能在Android5.0以上使用,目前還沒有提供RippleDrawable向下兼容的支持包。
RippleDrawable可顯示一個漣漪效應響應狀態變化 。

定義一個UI的背景圖片為RippleDrawable
android:background="@drawable/ripple"

在drawable文件夾下面定義一個RippleDrawable的xml文件

<?xml version="1.0" encoding="utf-8"?><ripple xmlns:android="http://schemas.android.com/apk/res/android"  android:color="#0000FF">  <item>    <shape android:shape="rectangle">      <solid android:color="#FFFFFF" />      <corners android:radius="4dp" />    </shape>  </item></ripple> 

android:color :表示波紋的顏色

<item>:表示波紋圖下面的條目

來看一下點擊按鈕的波紋效果

android,5.0新控件,新控件

5. RecyclerView(循環視圖)

RecyclerView是ListView的替代品,谷歌推薦使用RecyclerView替代ListView。

RecyclerView提供比ListView更加靈活的使用,并且性能比ListView更優。

RecyclerView可以設置線性,網格,瀑布流式三種布局管理器。

- LinearLayoutManager(線性布局管理器)
- GridLayoutManager(網格布局管理器)
- StaggeredGridLayoutManager(瀑布流式布局管理器)

注意:RecyclerView,Patelle,CardView是在單獨的支持包里面,不在appcompat-v7及其依賴子包中

 要使用它們,必須導入它們的依賴包

 compile 'com.android.support:recyclerview-v7:23.1.1'  compile 'com.android.support:palette-v7:23.1.1'  compile 'com.android.support:cardview-v7:23.1.1' 


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 武功县| 沽源县| 关岭| 宿松县| 宝清县| 武胜县| 景谷| 大石桥市| 精河县| 东阳市| 广灵县| 锦州市| 绥滨县| 伊金霍洛旗| 军事| 大埔区| 新丰县| 恩施市| 桃江县| 凉城县| 桃园县| 陵川县| 新沂市| 兴安县| 柞水县| 海丰县| 湘潭县| 阿克苏市| 弥勒县| 石河子市| 英吉沙县| 温泉县| 阿合奇县| 宁乡县| 徐水县| 德阳市| 乌拉特前旗| 隆尧县| 镇江市| 马山县| 新化县|