建立Material Design風格的Android應用--應用主題,materialandroid
本人所有文章首先發佈於個人部落格,歡迎關注,地址:http://blog.isming.me
昨天正式發布了android 5,同時android developer網站也更新了,增加了建立Material Design風格的Android應用指南,也更新了Support Library,在support library增加了一些Material Design風格的控制項和動畫等,這裡給大家簡單介紹一下怎樣開發material design風格的Android應用。
android 5使用Material Design風格
android提供了三種Material Design風格Theme。
分別是:
@android:style/Theme.Material (dark version) @android:style/Theme.Material.Light (light version) @android:style/Theme.Material.Light.DarkActionBar
Light material theme
Light material theme
Dark material theme
Dark material theme
我們可以以這三個Theme來定義我們的Theme,比如:
<resources> <!-- inherit from the material theme --> <style name="AppTheme" parent="android:Theme.Material"> <!-- Main theme colors --> <!-- your app branding color for the app bar --> <item name="android:colorPrimary">@color/primary</item> <!-- darker variant for the status bar and contextual app bars --> <item name="android:colorPrimaryDark">@color/primary_dark</item> <!-- theme UI controls like checkboxes and text fields --> <item name="android:colorAccent">@color/accent</item> </style></resources>
我們可以修改每個位置的字或者背景的顏色,每個位置的名字如所示:
Customizing the material theme
我就簡單的介紹一下,更具體的自己探索吧。
較低版本使用Material Design風格
要在較低版本上面使用Material Design風格,則需要使用最新的support library(version 21),可以直接把項目引入工程,或者使用gradle構建,增加compile dependency:
dependencies { compile 'com.android.support:appcompat-v7:+' compile 'com.android.support:cardview-v7:+' compile 'com.android.support:recyclerview-v7:+'}
將上面的AppTheme style放到res/values-v21/style.xml,再res/values/style.xml增加一個AppTheme,如下:
<!-- extend one of the Theme.AppCompat themes --><style name="Theme.MyTheme" parent="Theme.AppCompat.Light"> <!-- customize the color palette --> <item name="colorPrimary">@color/material_blue_500</item> <item name="colorPrimaryDark">@color/material_blue_700</item> <item name="colorAccent">@color/material_green_A200</item></style>
這樣可以同樣實現很多的地方是Material Design,但是由於低版本不支援沈浸式狀態列,有一些效果還是無法實現。
PS:就寫這麼多吧。下次寫使用CardView 和RecyclerView。做Material Design的List 和Card布局。 (我英文不好,可能有些地方也理解的不好。)
參考:http://developer.android.com/training/material/theme.html
原文地址:http://blog.isming.me/2014/10/18/creating-android-app-with-material-design-one-theme/,轉載請註明出處。
Material Design是什?
Google推出了全新的設計語言Material Design。Google表示,這種設計語言旨在為手機、平板電腦、台式機和“其他平台”提供更一致、更廣泛的“外觀和感覺”。
Google安卓作業系統使用者體驗主管馬蒂亞斯·杜拉特(Matias Durate)在今天的I/O開發人員大會主題演講中表示:“我們想象著,如果像素不僅有顏色,還有深度,那會是怎樣的一番情景?如果有一種材料可以改變它的質地,那又會如何?這種暢想最終讓我們開發出了我們稱之為Material Design的設計語言。”
Material Design語言的一些重要功能包括 系統字型Roboto的升級版本 ,同時顏色更鮮豔,動畫效果更突出。杜拉特還簡要談到了新架構的一些變化——這個新架構也於今天在 google.com/design 公開發布。Google的想法是讓Google平台上的開發人員掌握這個新架構,從而讓所有應用就有統一的外觀,就像是蘋果向開發人員提出的設計原則一樣。
Google還基於這種新的設計語言對本公司旗艦應用進行了重新設計,包括安卓和網頁端的Gmail和Calendar。大家可能還會記得,最近曾看到過有關這些變動的文章, 有些部落格 已經掌握了外泄截屏,顯示經過了重新設計的Gmail,介面更乾淨、更簡約。
在安卓平台上,這種新介面被稱為Material,支援各種新動畫效果,具有內建的即時UI陰影,以及可在不同螢幕之間切換的hero元素。
怎看安卓應用是不是按照Android Design開發的?
import java.io.CharArrayReader;import java.util.Arrays;import java.util.Scanner;
public class Test {
public static void main(String[] args) { // first(); // second(); // third(); // fourth(); // fifthly(); // sixth(); // zimuduiying(); // Xunhuan(); Max();
}
/** * "根據以下要求,比較兩個字串的大小,並返回比較結果: 1、比較兩字串的大小。 2、忽視大小寫 3、 按字典序 如果第一個字串大於第二個字串 * 返回大於0,如果第一個字串等於第二個字串 返回等於0 ,如果第一個字串小於第二個字串返回小於0。 4、例子 * compareToIgnoreCase(“HARD”,”hark”)的比較結 果返回小於0 。" */
public static void first() { String a = "HARK"; String b = "hello"; if ((a.compareToIgnoreCase(b)) > 0) { System.out.println("1"); } else if ((a.compareToIgnoreCase(b)) < 0) { System.out.println("-1"); } else { System.out.println("0"); } }
/** * " 給一個二維數組inArr[ ][ ],寫一個方法擷取每一列的最小值,輸出到一個一維數組outArr[ ]中。 如:inArr[ ][ * ]={{1,8,3},{6,5}},則輸出outArr[ ] = {1,5,3} " */ public static void second() { int inArray[][] = { { 1, 8, 3 }, { 6, 5 } }; int outArray[] = new int[3]; int min = 0;
for (int col = 0; col < 3; col++) { int row = 0; try { min = inArray[row][col];
} catch (ArrayIndexOutOfBoundsException e) { row++;// 如果越界row在加一行 min = inArray[row][col]; } for (row = 0; row < outArray.length; row++) { try { if (min > inArray[row][col]) { min = inArray[row][col]; } } catch (Exception e) { contin......餘下全文>>