android安卓涵盖大多基础xml文件使用的介绍
2017-06-27 15:18
435 查看
1, values ---> colors 获取颜色值:
<color name="gray">#3F51B5</color>
运用:xml文件中: android:background="@color/gray"
2, values ---> dimens 获取尺寸:
<dimen name="text_size6">6dp</dimen> <dimen name="text_size16">16dp</dimen> <dimen name="text_size18">18dp</dimen> <dimen name="text_size19">19dp</dimen> <dimen name="text_size20">20dp</dimen>
运用:xml文件中: android:textSize="@dimen/text_size6"/>
3, values ---> string 获取字符串:
<string name="action_settings" translatable="false">设置</string>
运用:xml文件中: android:title="@string/action_settings"
4, values ---> styles: 获取类型:
<!--红包--> <style name="dialog_Fullscreen" > <item name="android:windowBackground">@color/transparent</item> <item name="android:windowNoTitle">true</item> <item name="android:windowFullscreen">true</item> <item name="android:windowIsTranslucent">true</item> <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item> </style>
运用:代码中(比如在继承的Dialog中):
public LuckMoneyDialog(Context context, List<LuckMoney> luckMoneyList) { super(context, R.style.dialog_Fullscreen); mList = luckMoneyList; mContext = context; initContent(); }
#:以上是android中自带的,下面是由自定义的xml资源文件.
5,获取资源文件的字符串数组 values ---> attrs.xml文件:
<string-array name="price_list_names"> <!--<item>当地包天无限流量套餐</item>--> <item>标准流量资费</item> <item>拨打中国大陆</item> <item>当地接听</item> <item>拨打当地</item> <item>拨打其他国家地区</item> <item>发短信至中国大陆</item> <item>发短信至其他国家地区</item> <item>当地收短信</item> </string-array>
运用:String[] names = context.getResources().getStringArray(R.array.price_list_names);
##:int数组:integer-array
6, xml文件方式实现动画 :自定义anim文件夹 ---> 自定义命名文件,比如:loading.xml文件:
文件内容:
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <translate android:duration="500" android:fromXDelta="100%p" android:toXDelta="0%p" /> </set>
运用开始某动画:mFivIcon.startAnimation(AnimationUtils.loadAnimation(Context,
R.anim.loading)); //mFivIcon为某控件
# 这实际上是用xml文件的方式来开始动画,当然如果你喜欢代码的方式来实现也可.
7, 背景选择器 drawable ---> 自定义命名文件,比如:btn_color.xml文件:
文件内容:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@color/press" android:state_pressed="true" /> <item android:drawable="@color/press" android:state_focused="true"/> <item android:drawable="@color/press" android:state_selected="true"/> <item android:drawable="@color/press_no" /> </selector>
# press为color下一个颜色值:<color name="press">#35ff0000</color>
当然这里也可以是drawable下的一个xml文件.
android:state_selected--------选中
android:state_focused--------获得焦点
android:state_pressed--------点击
运用:
xml文件中:android:background="@drawable/btn_color"
代码中:btn.setBackground(getResources().getDrawable(R.drawable.btn_color));
8, 加边框和圆角 drawable ---> 自定义命名文件,比如: dialog_phone_status.xml文件:作为背景,加边框
文件内容:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <corners android:radius="8dp" /> <solid android:color="#ffffff" /> <stroke android:width="1dp" android:color="#9f9f9f" > </stroke> <!-- 与边框的距离 --> <padding android:bottom="3dp" android:left="3dp" android:right="3dp" android:top="3dp" /> </shape>
9, 不仅要圆角的button,而且点击变色
就是selector与shape的混合使用:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true"><shape> <corners android:radius="5.0dp" /> <solid android:color="#906EA2FC" /> <stroke android:width="2dp" android:color="#50ff0000" > </stroke> <!-- 与边框的距离 --> <padding android:bottom="3dp" android:left="3dp" android:right="3dp" android:top="3dp" /> </shape></item> <item android:state_pressed="false"><shape> <corners android:radius="5.0dp" /> <solid android:color="#6EA2FC" /> </shape></item> </selector>
相关文章推荐
- Android基础的xml文件创建,解析,以及安卓下的消息机制
- 在android中使用Pull解析器生成xml文件
- Android使用Pull解析器解析XML文件
- android使用xml布局文件设计提示对话框
- Android -使用DOM(文档对象模型)解析XML文件
- 在AndroidManifest.xml文件中键盘和自适应的android:windowSoftInputMode属性使用 | keyboard,squeezing,layout
- android_xml解析之 使用PULL读取XML文件 .
- 在AndroidManifest.xml文件中的android:windowSoftInputMode属性使用
- Android深入浅出系列课程---Lesson4-AAF110429_介绍Manifest文件的使用
- Android --- 使用SAX读取xml文件
- 在AndroidManifest.xml文件中<activity>的android:windowSoftInputMode属性使用
- android的XML布局文件上使用自定义的类
- jni使用基础(三)之Android.mk文件详解
- 【Android】简易音乐播放器(介绍使用Service和Broadcast播放音乐文件)
- AndroidManifest.xml文件中的android:windowSoftInputMode属性使用
- android 使用 pull 解析xml文件
- Android的AIDL文件使用入门介绍
- xml文件介绍及使用
- android 的 AndroidManifest.xml 文件介绍