最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

android 開發(fā)教程之日歷項目實踐(三)

 更新時間:2013年01月03日 15:19:57   作者:  
決定開始學習 Android 平臺下的軟件開發(fā),以日歷作為實踐項目,進行一周后,基本完成,有需要的朋友可以參考下

二、創(chuàng)建樣式

日歷顯示的表格線,使用 Cell 填充圖形的邊框來實現(xiàn),為了統(tǒng)一,我們先定義邊框線的顏色及線條精細。

另外還要定義一系統(tǒng)填充樣式等。

創(chuàng)建 color

color_calendar_border 表格線
color_calendar_title_gregorian 標題欄日期年月文字的顏色color_calendar_title_lunar 標題欄農(nóng)歷color_calendar_title_startcolor_calendar_title_endcolor_calendar_title_addition 標題欄 節(jié)日,節(jié)氣color_calendar_weekindex 年單位周序號color_calendar_weekindex_backgroundcolor_calendar_weekend 周末color_calendar_weekend_backgroundcolor_calendar_header 表頭color_calendar_header_backgroundcolor_calendar_outrange 非本月日期color_calendar_outrange_backgroundcolor_calendar_normal_gregorian 公歷日期color_calendar_normal_lunar  農(nóng)歷日期color_calendar_normal_backgroundcolor_calendar_today_gregorian 今天公歷日期color_calendar_today_lunar 今天農(nóng)歷日期color_calendar_today_backgroundcolor_calendar_solarterm 節(jié)氣color_calendar_festival 節(jié)日color_calendar_pressed 點擊單元格填充背景
color_calendar_focused 焦點單元格填充背景

點擊 下圖 菜單 Search 下面的圖標(New Android XML File)

選擇 Resource Type -> Values,輸入文件名 -> colors,選擇 Root Element -> resources,點擊 Finish。


定義 color_calendar_border

復(fù)制代碼 代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="color_calendar_border">#3fff</color>
<color name="color_calendar_title_gregorian">#cfff</color>
<color name="color_calendar_title_lunar">#cfff</color>
<color name="color_calendar_title_start">#c000</color>
<color name="color_calendar_title_end">#6000</color>
<color name="color_calendar_title_addition">#f63</color>
<color name="color_calendar_weekindex">#3fff</color>
<color name="color_calendar_weekindex_background">#369f</color>
<color name="color_calendar_weekend">#9fff</color>
<color name="color_calendar_weekend_background">#3f99</color>
<color name="color_calendar_header">#9fff</color>
<color name="color_calendar_header_background">#6000</color>
<color name="color_calendar_outrange">#3fff</color>
<color name="color_calendar_outrange_background">#3fff</color>
<color name="color_calendar_normal_gregorian">#cfff</color>
<color name="color_calendar_normal_lunar">#9fff</color>
<color name="color_calendar_normal_background">#0000</color>
<color name="color_calendar_today_gregorian">#cfff</color>
<color name="color_calendar_today_lunar">#9fff</color>
<color name="color_calendar_today_background">#06c</color>
<color name="color_calendar_solarterm">#c0c3</color>
<color name="color_calendar_festival">#cf90</color>
<color name="color_calendar_pressed">#306c</color>
<color name="color_calendar_focused">#606c</color>
</resources>

Color 的值由四部分組成:透明度,Red, Green, Blue,每部分可以用一位或兩位十六進制數(shù)字表示,透明度可以省略。

如:

  ffff 或 ffffffff 表示不透明白色,前面的透明度可以省略:fff 或 ffffff

  7f00 表示半透明的紅色

更多請查看:http://developer.android.com/guide/topics/resources/more-resources.html#Color

將顏色定義統(tǒng)一放在一個文件中,是出于兩點考慮,一是多處用到同一種顏色定義,這樣一處修改,相應(yīng)的位置都會跟著變,另外則是為了修改方便,無須到處去找某一個文件。上面的 color_calendar_border 被表格的各種狀態(tài)填充圖形用到,而像 color_calendar_weelndex_background 只有一處用到,如果不想統(tǒng)一管理,也可以不在這里定義,在定義 shape 時,直接使用固定值。

創(chuàng)建 dimen

點擊 下圖 菜單 Search 下面的圖標(New Android XML File)




選擇 Resource Type -> Values,輸入文件名 -> dimens,選擇 Root Element -> resources,點擊 Finish。

完成的 xml 文件內(nèi)容:

復(fù)制代碼 代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="dimen_calendar_border">1dp</dimen>

</resources>

尺寸的單位主要有六種:dp, sp, pt, px, mm, in,更多介紹請參照:http://developer.android.com/guide/topics/resources/more-resources.html#Dimension

創(chuàng)建 Color State List

在我們的日歷中,單元格有三種狀態(tài),分別是無焦點,按下,有焦點,為了在不同的狀態(tài)下顯示不同的顏色,可以定義 Color State List。

關(guān)于 Color State List,更多請參照:http://developer.android.com/guide/topics/resources/color-list-resource.html。

Color State List 列表

colorlist_calendar_normal
colorlist_calendar_outrange
colorlist_calendar_weekend
colorlist_calendar_today

點擊 下圖 菜單 Search 下面的圖標(New Android XML File)

選擇 Resource Type -> Drawable,輸入文件名 -> colorlist_calendar_outrange,選擇 Root Element -> selector,點擊 Finish。

完成的 xml 文件
復(fù)制代碼 代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="@color/color_calendar_pressed"/>
<item android:state_focused="true" android:color="@color/color_calendar_focused"/>
<item android:color="@color/color_calendar_outrange_background"/>
</selector>

其它也同樣創(chuàng)建。

創(chuàng)建的 drawable

shape_calendar_titlebar.xml 主畫面標題欄填充背景shape_calendar_header.xml 表頭填充背景shape_calendar_cell_weekindex.xml 年為單元的周序號單元格填充背景shape_calendar_cell_weekend.xml 周末日期單元格填充背景shape_calendar_cell_normal.xml 當月普通日期單元格填充背景shape_calendar_cell_outrange.xml 非當前月日期單元格填充背景shape_calendar_cell_today.xml 今天單元格填充背景

點擊 下圖 菜單 Search 下面的圖標(New Android XML File)

選擇 Resource Type -> Drawable,輸入文件名 -> shpae_calendar_titlebar,選擇 Root Element -> shape,點擊 Finish。

輸入 shape 定義

復(fù)制代碼 代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="3dp" />
<gradient android:angle="90"
android:startColor="@color/color_calendar_title_start"
android:endColor="@color/color_calendar_title_end"
/>
</shape>

這段定義代碼會幫我們生成一個圓角矩形,填充顏色是上下漸變的。

radius = 圓角大小

angle = 漸變填充方向(45的位數(shù),0-360,90 表示從上往下漸變填充)

startColor, endColor = 填充的起始與終止顏色定義

其它的也按此一一創(chuàng)建,但表格的填充矩形,不要圓角,刪除 radius 或設(shè)為 0

如:shape_calendar_cell_outrange.xml

復(fù)制代碼 代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/colorlist_calendar_outrange" />
<stroke android:width="@dimen/dimen_calendar_border"
android:color="@color/color_calendar_border" />
</shape>

solid = 填充色,這里用前面定義的 color state list,來實現(xiàn)不同狀態(tài)下,填充不同顏色。

stroke = 矩形邊框,width = 邊框線粗細, color = 邊框線顏色

創(chuàng)建 style

打開 res/styles.xml,添加樣式定義。由于樣式與畫面設(shè)計相關(guān),在我們設(shè)計界面時,還要相應(yīng)調(diào)整,所以在使用時,一一添加。這里給出一個 sample:

復(fù)制代碼 代碼如下:

<resources xmlns:android="http://schemas.android.com/apk/res/android">

<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>

<style name="style_calendar_title">
<item name="android:background">@drawable/shape_calendar_titlebar</item>
</style>

<style name="style_calendar_title_gregorian">
<item name="android:textSize">36sp</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">@color/color_calendar_title_gregorian</item>
<item name="android:layout_marginLeft">25dp</item>
</style>
... ...
</resources>

相關(guān)文章

  • 從0快速搭建一個實用的MVVM框架(超詳細)

    從0快速搭建一個實用的MVVM框架(超詳細)

    這篇文章主要介紹了從0搭建一個實用的MVVM框架,結(jié)合Jetpack,構(gòu)建快速開發(fā)的MVVM框架,支持快速生成ListActivity、ListFragment,主要是基于MVVM進行快速開發(fā)上手即用,需要的朋友可以參考下
    2022-03-03
  • 基于Android XML解析與保存的實現(xiàn)

    基于Android XML解析與保存的實現(xiàn)

    本篇文章小編為大家介紹,基于Android XML解析與保存的實現(xiàn)。需要的朋友參考下
    2013-04-04
  • Android Tiny集成圖片壓縮框架的使用

    Android Tiny集成圖片壓縮框架的使用

    本篇文章主要介紹了Android Tiny集成圖片壓縮框架的使用,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-09-09
  • Android實現(xiàn)一個簡易的帶邊輸入框

    Android實現(xiàn)一個簡易的帶邊輸入框

    如今市面上APP的輸入框可以說是千奇百怪,不搞點花樣出來貌似代表格局沒打開,還在使用系統(tǒng)自帶的輸入框的兄弟可以停下腳步,哥帶你實現(xiàn)一個簡易的帶邊框輸入框,感興趣的同學可以自己動手試一下
    2023-08-08
  • Android Canvas和Bitmap結(jié)合繪圖詳解流程

    Android Canvas和Bitmap結(jié)合繪圖詳解流程

    在 Android Canvas 上繪圖非常難,在繪圖時需要理解許多不同的類和概念。這篇文章中,將介紹 Android 框架中可用的一些類,它們可以讓畫布使用時更輕松
    2021-11-11
  • Android實現(xiàn)淘寶客戶端倒計時界面

    Android實現(xiàn)淘寶客戶端倒計時界面

    這篇文章主要為大家詳細介紹了Android實現(xiàn)淘寶客戶端倒計時界面,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-04-04
  • Flutter?fluro時報錯type?'String'?is?not?a?subtype?of?type?'Queue<Task>'

    Flutter?fluro時報錯type?'String'?is?not?a?subty

    這篇文章主要介紹了Flutter使用fluro時報錯type?'String'?is?not?a?subtype?of?type?'Queue<Task>'解決方法詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助
    2023-12-12
  • Kotlin定義其他類的實現(xiàn)詳解

    Kotlin定義其他類的實現(xiàn)詳解

    這篇文章主要介紹了Kotlin定義其他類的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2022-09-09
  • Android最簡單的限制輸入方法(只包含數(shù)字、字母和符號)

    Android最簡單的限制輸入方法(只包含數(shù)字、字母和符號)

    這篇文章主要給大家介紹了關(guān)于Android最簡單的限制輸入的實現(xiàn)方法,限制輸入框只能輸入數(shù)字、字母和符號,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面來一起看看 吧
    2018-11-11
  • Android 實現(xiàn)左滑出現(xiàn)刪除選項

    Android 實現(xiàn)左滑出現(xiàn)刪除選項

    滑動刪除的部分主要包含兩個部分, 一個是內(nèi)容區(qū)域(用于放置正常顯示的view),另一個是操作區(qū)域(用于放置刪除按鈕)。下面通過本文給大家介紹Android 實現(xiàn)左滑出現(xiàn)刪除選項,需要的朋友可以參考下
    2017-06-06

最新評論

永春县| 光山县| 亳州市| 达尔| 克山县| 扶沟县| 安达市| 中卫市| 神农架林区| 六枝特区| 镇赉县| 广元市| 沅江市| 昌图县| 微山县| 察隅县| 贵溪市| 镇康县| 明光市| 渝中区| 新晃| 万州区| 吉木乃县| 德令哈市| 通河县| 洛宁县| 南安市| 临汾市| 桃园市| 从化市| 木兰县| 古浪县| 玉林市| 石狮市| 安塞县| 从江县| 云南省| 栾城县| 乐业县| 轮台县| 肥城市|