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

android 開發(fā)教程之日歷項(xiàng)目實(shí)踐(三)

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

二、創(chuàng)建樣式

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

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

創(chuàng)建 color

color_calendar_border 表格線
color_calendar_title_gregorian 標(biāo)題欄日期年月文字的顏色color_calendar_title_lunar 標(biāo)題欄農(nóng)歷color_calendar_title_startcolor_calendar_title_endcolor_calendar_title_addition 標(biāo)題欄 節(jié)日,節(jié)氣color_calendar_weekindex 年單位周序號(hào)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 點(diǎn)擊單元格填充背景
color_calendar_focused 焦點(diǎn)單元格填充背景

點(diǎn)擊 下圖 菜單 Search 下面的圖標(biāo)(New Android XML File)

選擇 Resource Type -> Values,輸入文件名 -> colors,選擇 Root Element -> resources,點(diǎn)擊 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,每部分可以用一位或兩位十六進(jìn)制數(shù)字表示,透明度可以省略。

如:

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

  7f00 表示半透明的紅色

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

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

創(chuàng)建 dimen

點(diǎn)擊 下圖 菜單 Search 下面的圖標(biāo)(New Android XML File)




選擇 Resource Type -> Values,輸入文件名 -> dimens,選擇 Root Element -> resources,點(diǎn)擊 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,更多介紹請(qǐng)參照:http://developer.android.com/guide/topics/resources/more-resources.html#Dimension

創(chuàng)建 Color State List

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

關(guān)于 Color State List,更多請(qǐng)參照: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

點(diǎn)擊 下圖 菜單 Search 下面的圖標(biāo)(New Android XML File)

選擇 Resource Type -> Drawable,輸入文件名 -> colorlist_calendar_outrange,選擇 Root Element -> selector,點(diǎn)擊 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 主畫面標(biāo)題欄填充背景shape_calendar_header.xml 表頭填充背景shape_calendar_cell_weekindex.xml 年為單元的周序號(hào)單元格填充背景shape_calendar_cell_weekend.xml 周末日期單元格填充背景shape_calendar_cell_normal.xml 當(dāng)月普通日期單元格填充背景shape_calendar_cell_outrange.xml 非當(dāng)前月日期單元格填充背景shape_calendar_cell_today.xml 今天單元格填充背景

點(diǎn)擊 下圖 菜單 Search 下面的圖標(biāo)(New Android XML File)

選擇 Resource Type -> Drawable,輸入文件名 -> shpae_calendar_titlebar,選擇 Root Element -> shape,點(diǎn)擊 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>

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

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,來實(shí)現(xiàn)不同狀態(tài)下,填充不同顏色。

stroke = 矩形邊框,width = 邊框線粗細(xì), color = 邊框線顏色

創(chuàng)建 style

打開 res/styles.xml,添加樣式定義。由于樣式與畫面設(shè)計(jì)相關(guān),在我們?cè)O(shè)計(jì)界面時(shí),還要相應(yīng)調(diào)整,所以在使用時(shí),一一添加。這里給出一個(gè) 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快速搭建一個(gè)實(shí)用的MVVM框架(超詳細(xì))

    從0快速搭建一個(gè)實(shí)用的MVVM框架(超詳細(xì))

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

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

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

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

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

    Android實(shí)現(xiàn)一個(gè)簡(jiǎn)易的帶邊輸入框

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

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

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

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

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

    Flutter?fluro時(shí)報(bào)錯(cuò)type?'String'?is?not?a?subty

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

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

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

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

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

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

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

最新評(píng)論

许昌市| 乌鲁木齐县| 武鸣县| 宝山区| 马关县| 铜山县| 句容市| 苍山县| 洪湖市| 玉林市| 江达县| 德昌县| 宜城市| 迁安市| 海兴县| 汤阴县| 闸北区| 尚志市| 合作市| 武鸣县| 大同市| 长岭县| 营口市| 右玉县| 巍山| 公主岭市| 启东市| 阿鲁科尔沁旗| 安仁县| 五河县| 武平县| 苏尼特右旗| 房产| 崇信县| 聊城市| 平泉县| 武鸣县| 历史| 南安市| 合水县| 望都县|