Android開(kāi)發(fā)之資源文件用法實(shí)例總結(jié)
本文實(shí)例總結(jié)了Android開(kāi)發(fā)之資源文件用法。分享給大家供大家參考,具體如下:
這里記錄在Android開(kāi)發(fā)中經(jīng)常用到的一些用法
arrays.xml定義數(shù)組
例:
<resources>
<!-- share items -->
<string-array name="app_share_items">
<item>新浪微博</item>
<item>騰訊微博</item>
</string-array>
</resources>
純色圓角背景
<shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#4a90e2" /> <corners android:radius="95dp" /> </shape>
用法:
android:background="@drawable/xml_background_button_blue"
要獲取這種背景所對(duì)應(yīng)的類(lèi)型為:Drawable:GradientDrawable,我們可以改變它的顏色,而保持背景不變。
顏色相關(guān)
ps中:0透明,1完全不透
android:顏色格式:argb alpha:[0,255] 完全透明到完全不透明
粉紅:#8f0f
uses-permission
彈窗口時(shí),在Manifest中添加:
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
資源文件與類(lèi)的對(duì)應(yīng)關(guān)系
selector對(duì)應(yīng)的是StateList
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/xml_login_button_press"/> <item android:drawable="@drawable/xml_login_button_normal"/> </selector>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape>
<solid android:color="@color/pressed_color"/>
</shape>
</item>
<item>
<shape>
<solid android:color="@color/transparent"/>
</shape>
</item>
</selector>
shape 對(duì)應(yīng)的是GradientDrawable
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#4a90e2" /> <corners android:radius="95dp" /> </shape>
Notification
1. Action與Activity關(guān)聯(lián)
以下兩步缺一不可
step1: 指定一個(gè)Action常量:
public static final String DOWNLOAD_MANAGER = "com.james.app.download";
step2:在對(duì)應(yīng)的Activity中指定對(duì)應(yīng)的IntentFilter
<intent-filter> <action android:name="com.james.app.download"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter>
2. Notification是通過(guò)Action來(lái)區(qū)別的,不是通過(guò)ID來(lái)區(qū)別的
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專(zhuān)題:《Android資源操作技巧匯總》《Android開(kāi)發(fā)入門(mén)與進(jìn)階教程》、《Android控件用法總結(jié)》、《Android短信與電話(huà)操作技巧匯總》及《Android多媒體操作技巧匯總(音頻,視頻,錄音等)》
希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。
相關(guān)文章
Android 中添加水平線(xiàn)和垂直線(xiàn)方法總結(jié)
這篇文章主要介紹了Android 中添加水平線(xiàn)和垂直線(xiàn)方法總結(jié)的相關(guān)資料,需要的朋友可以參考下2017-02-02
Android仿iOS側(cè)滑退出當(dāng)前界面功能
這篇文章主要為大家詳細(xì)介紹了Android仿iOS側(cè)滑退出當(dāng)前界面功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-12-12
Android的App啟動(dòng)時(shí)白屏的問(wèn)題解決辦法
這篇文章主要介紹了Android的App啟動(dòng)時(shí)白屏的問(wèn)題相關(guān)資料,在App啟動(dòng)的第一次的時(shí)候白屏?xí)欢螘r(shí)間,這里提供了解決辦法,需要的朋友可以參考下2017-08-08
Android RecyclerView實(shí)現(xiàn)數(shù)據(jù)列表展示效果
這篇文章主要為大家詳細(xì)介紹了Android RecyclerView實(shí)現(xiàn)數(shù)據(jù)列表展示效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-07-07
百度地圖實(shí)現(xiàn)小車(chē)規(guī)劃路線(xiàn)后平滑移動(dòng)功能
這篇文章主要介紹了百度地圖實(shí)現(xiàn)小車(chē)規(guī)劃路線(xiàn)后平滑移動(dòng)功能,本文是小編寫(xiě)的一個(gè)demo,通過(guò)效果圖展示的非常直白,需要的朋友可以參考下2020-01-01
Android開(kāi)發(fā)之獲取網(wǎng)絡(luò)鏈接狀態(tài)
這篇文章主要介紹了Android獲取網(wǎng)絡(luò)鏈接狀態(tài)的方法,主要是通過(guò)ConnectivityManager類(lèi)來(lái)完成的,需要的朋友可以參考下2014-08-08

