Android样式的开发:Style篇
来源:互联网 发布:亚像素边缘检测算法 编辑:程序博客网 时间:2024/04/29 13:46
转载自Keegan小钢 原文链接:http://keeganlee.me/post/android/20151031
- 每个页面标题栏的标题基本会有一样的字体大小、颜色、对齐方式、内间距、外间距等,这就可以定义成样式;
- 很多按钮也都使用一致的背景、内间距、文字颜色、文字大小、文字的对齐方式等,这也可以定义成样式;
- 网络加载的进度条基本也都是一样的,同样可以定义成样式;
- 不喜欢系统的弹出框样式,那也可以自定义样式。
样式的定义
<style name="Widget.Material.Button"> <item name="background">@drawable/btn_default_material</item> <item name="textAppearance">?attr/textAppearanceButton</item> <item name="minHeight">48dip</item> <item name="minWidth">88dip</item> <item name="stateListAnimator">@anim/button_state_list_anim_material</item> <item name="focusable">true</item> <item name="clickable">true</item> <item name="gravity">center_vertical|center_horizontal</item></style>
<!-- res/anim/button_state_list_anim_material.xml --><?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:state_enabled="true"> <set> <objectAnimator android:propertyName="translationZ" android:duration="@integer/button_pressed_animation_duration" android:valueTo="@dimen/button_pressed_z_material" android:valueType="floatType" /> <objectAnimator android:propertyName="elevation" android:duration="0" android:valueTo="@dimen/button_elevation_material" android:valueType="floatType" /> </set> </item> <!-- base state --> <item android:state_enabled="true"> <set> <objectAnimator android:propertyName="translationZ" android:duration="@integer/button_pressed_animation_duration" android:valueTo="0" android:startDelay="@integer/button_pressed_animation_delay" android:valueType="floatType"/> <objectAnimator android:propertyName="elevation" android:duration="0" android:valueTo="@dimen/button_elevation_material" android:valueType="floatType" /> </set> </item> <item> <set> <objectAnimator android:propertyName="translationZ" android:duration="0" android:valueTo="0" android:valueType="floatType"/> <objectAnimator android:propertyName="elevation" android:duration="0" android:valueTo="0" android:valueType="floatType"/> </set> </item></selector>
<!-- res/values/styles.xml --><resources> <style name="ButtonNormal" parent="@android:style/Widget.Material.Button" > <item name="android:background">@drawable/bg_btn_selector</item> <item name="android:textColor">@color/text_btn_selector</item> </style></resources>
<!-- res/values/styles.xml --><resources> <style name="ButtonNormal" parent="@android:style/Widget.Material.Button"> <item name="android:background">@drawable/bg_btn_selector</item> <item name="android:textColor">@color/text_btn_selector</item> </style> <style name="ButtonNormal.Transparent"> <item name="android:background">@drawable/bg_btn_transparent</item> <item name="android:textColor">@color/text_btn_selector</item> </style></resources>
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="onAction" android:text="@string/btn_action" style="@style/ButtonNormal.Transparent" />
styles.xmlstyles_device_defaults.xmlstyles_holo.xmlstyles_leanback.xmlstyles_material.xmlstyles_micro.xmlthemes.xmlthemes_device_defaults.xmlthemes_holo.xmlthemes_leanback.xmlthemes_material.xmlthemes_micro.xml
主题
- themes.xml:低版本的主题,目标API level一般为10或以下
- themes_holo.xml:从API level 11添加的主题
- themes_device_defaults.xml:从API level 14添加的主题
- themes_material.xml:从API level 21添加的主题
- themes_micro.xml:应该是用于Android Wear的主题
- themes_leanback.xml: 还不清楚什么用
<resources> <style name="AppTheme" parent="Theme.AppCompat"> <item name="windowActionBar">false</item> <item name="windowNoTitle">true</item> <item name="windowAnimationStyle">@style/WindowAnimation</item> </style> <!-- Standard animations for a full-screen window or activity. --> <style name="WindowAnimation" parent="@android:style/Animation.Activity"> <item name="activityOpenEnterAnimation">@anim/activity_open_enter</item> <item name="activityOpenExitAnimation">@anim/activity_open_exit</item> <item name="activityCloseEnterAnimation">@anim/activity_close_enter</item> <item name="activityCloseExitAnimation">@anim/activity_close_exit</item> </style></resources>
<!-- res/anim/activity_close_exit.xml --><?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false" android:zAdjustment="top"> <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:interpolator="@interpolator/decelerate_quart" android:fillEnabled="true" android:fillBefore="false" android:fillAfter="true" android:duration="200" /> <translate android:fromYDelta="8%" android:toYDelta="0" android:fillEnabled="true" android:fillBefore="true" android:fillAfter="true" android:interpolator="@interpolator/decelerate_quint" android:duration="350" /></set>
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme"> <!-- activity here --></application>
0 0
- 【转载】Android样式的开发:Style篇
- Android样式的开发:Style篇
- Android样式的开发:Style篇
- Android样式的开发:Style篇
- Android样式的开发:Style篇
- Android样式的开发:Style篇
- Android样式的开发:Style篇
- Android样式的开发:Style篇
- Android样式的开发:Style篇
- Android样式的开发:Style篇
- Android样式的开发:Style篇
- ANDROID样式的开发:STYLE篇
- Android样式的开发(七):Style篇
- Android样式开发——style篇
- Android Style Resource --- style样式的定义
- Android系统的样式style
- android 样式style的设置
- android Style(样式)的解析
- ExploitExercises_Nebula_Level08
- uboot记录--收集
- HTTP的GET和POST格式解析
- android_13_使用XmlSerializer生成XML
- Atitit 知识管理的重要方法 数据来源,聚合,分类,备份,发布 搜索
- Android样式的开发:Style篇
- Apache Ant 扩展教程
- eclipse、myEclipse中接收中文乱码解决办法
- SNMP-MIB-SNMP4J简介
- 大数据资源如何管理
- 文章标题
- neutron callback system
- 遇上面试题的问题了
- PCM 转换为 WAV (java)