2017年2月22日 星期三

Styles and Themes

Styles and Themes



Styles and Themes:樣式與主題。



Defining Styles:在res/values/style,就可以定義標題、文字、顏色....等。android Styles是用<item>標籤,定義各個屬性。


Using Styles:


        res/layout/Mainactivity.xml 新增一行

        Style="@Style/XXXStyle"-->
       要在style.xml 宣告 Style name:XXXStyle。

  也可以直接<item name"colorR"(自己取)>#FF0000</item>
       android:textColor="@color/colorR"
  
       陰影屬性:

     shadowColor陰影顏色。

     shadowRadius陰影的粗細。
     
      shadowDx:陰影x方向的距離。
    
      shadowDy:陰影y方向的距離。


  Styles Inheriytance: Android支援很多網頁設計風格,可以用繼承現有的屬性方式,只要添加或修改自己需要的屬性。


      如果要每個Button都要同一個樣式,可以用Theme的機制,一次修改全部樣式。
      1.res/values/style.xml 新增/自訂主題

      <style name =                  "MyThemeparent="android:style/Theme">
     裡面增加或修改的屬性
     </style>

      2. 在AndroidManifest.xml  更改android:theme=為
        android:theme="@style/MyTheme"

顏色應用於Theme的屬性:顏色可以應用在Theme屬性,例如:Window 背景、primary text color,可以加入<item>裡面,自訂主題顏色。

      res/values/style.xml 新增/自訂顏色
   <item name="android:windowBackground">@color/colorGreen</item>  
    @color/colorGreen----->要在color.xml新增

Using a Custom Nine-Patch With Buttons:一個可以伸縮的點陣圖圖像,Android會自動調整大小來容納顯示的內容。


    創造九宮格按鈕
   1.保存圖片位置---> res/drawable/my_nine_patch.png
   2. 定義新的樣式。
   3.新的按鈕樣式應用到自訂主題的按鈕樣式裡。

Android 主題:


      設定主題為所有活動:  開啟 AndroidManifest.xml
        <application android:theme="@style/CustomFontStyle">


    設定主題為只有一個活動:開啟 AndroidManifest.xml

      <activity    android:theme="@style/CustomFontStyle">


           Android定義的默認主題,使用parent屬性如下繼承這些號碼:開啟  res/values/style.xml

      <style name ="CustomTheme"         parent="android:Theme.Light">
....
    </style >



Styling the colour palette:


以下更改顏色都是在res/values/style.xml

    1.colorPrimary:App名稱背景顏色。

    2.colorPrimaryDark:螢幕最上面的狀態列顏色。
   3. textcolorPrimaryApp名稱文字顏色。
  
   4. windowBackgroundApp畫面的背景。
  
   5. navigationBarColor導航列顏色

Default Styles & Themes:你可以在R.style類別,所有可用的樣式。



  android Themes


參考文獻


Android - Styles and Themes

TextView Shadow 文字陰影

Android TextView加上陰影效果

繼承(Inheritance)

使用 Style 或 Theme 修改 Android 元件的外觀

使用 Android 主題

Android AppTheme 系統預設樣式android:Theme語法整理

Android Tutorial 第六堂(1)Material Design - Theme 與 Transition

Android 主题Theme

使用材料設計風格

Android系統自帶樣式

[Android] Styles and Themes 設定

Android application design with styles and themes - Tutorial

Developing Custom Themes

Android Styles and Themes Tutorial

[Android] 擺脫開啟第一個activity前的空白畫面(windowBackground)

Android 應用啟動介面自定義(windowBackground)

Android Nine Patch圖片及按鈕背景

使用Android SDK提供的Draw9Patch Tool

Android必知必會--NinePatch圖片製作

Android UI设计--半透明效果对话框及activity(可做遮罩层)(colorBackgroundCacheHint)

Color palette

material design palette

ANDROID – TOOLBAR STEP BY STEP(有介紹navigationBarColor)

[Android] Toolbar + 套用Navigation Drawer



沒有留言:

張貼留言