首页 > 系统 > Android > 正文

Android开发之资源文件用法实例总结

2019-10-24 20:23:34
字体:
来源:转载
供稿:网友
这篇文章主要介绍了Android开发之资源文件用法,结合实例形式总结分析了Android开发过程中针对资源文件的常见操作技巧,需要的朋友可以参考下
 

本文实例总结了Android开发之资源文件用法。分享给大家供大家参考,具体如下:

这里记录在Android开发中经常用到的一些用法

arrays.xml定义数组

例:

<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"

要获取这种背景所对应的类型为:Drawable:GradientDrawable,我们可以改变它的颜色,而保持背景不变。

颜色相关

ps中:0透明,1完全不透
android:颜色格式:argb alpha:[0,255] 完全透明到完全不透明
粉红:#8f0f

uses-permission

弹窗口时,在Manifest中添加:

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

资源文件与类的对应关系

selector对应的是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 对应的是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关联

以下两步缺一不可 
step1: 指定一个Action常量:

public static final String DOWNLOAD_MANAGER = "com.james.app.download";

step2:在对应的Activity中指定对应的IntentFilter

<intent-filter>  <action android:name="com.james.app.download"/>  <category android:name="android.intent.category.DEFAULT"/></intent-filter>

2. Notification是通过Action来区别的,不是通过ID来区别的



注:相关教程知识阅读请移步到Android开发频道。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表