Android 开发常用样式(style)
2019-01-11 本文已影响14人
wuchao226
开发中常用的通用样式
在values目录中创建 styles_base.xml文件
//styles_base.xml
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="WrapMatch">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">match_parent</item>
</style>
<style name="MatchWrap">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
</style>
<style name="WrapWrap">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>
<style name="MatchMatch">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">match_parent</item>
</style>
<style name="MatchAuto">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_weight">1</item>
<item name="android:layout_height">0dp</item>
</style>
<style name="AutoMatch">
<item name="android:layout_width">0dp</item>
<item name="android:layout_weight">1</item>
<item name="android:layout_height">match_parent</item>
</style>
<style name="WrapAuto">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_weight">1</item>
<item name="android:layout_height">0dp</item>
</style>
<style name="AutoWrap">
<item name="android:layout_width">0dp</item>
<item name="android:layout_weight">1</item>
<item name="android:layout_height">wrap_content</item>
</style>
<style name="WrapMatch.Vertical">
<item name="android:orientation">vertical</item>
</style>
<style name="WrapMatch.Horizontal">
<item name="android:orientation">horizontal</item>
</style>
<style name="MatchWrap.Vertical">
<item name="android:orientation">vertical</item>
</style>
<style name="MatchWrap.Horizontal">
<item name="android:orientation">horizontal</item>
</style>
<style name="WrapWrap.Vertical">
<item name="android:orientation">vertical</item>
</style>
<style name="WrapWrap.Horizontal">
<item name="android:orientation">horizontal</item>
</style>
<style name="MatchMatch.Vertical">
<item name="android:orientation">vertical</item>
</style>
<style name="MatchMatch.Common">
<item name="android:background">@color/common_bg</item>
</style>
<style name="MatchWrap.Common">
<item name="android:background">@color/common_bg</item>
</style>
<style name="MatchMatch.Vertical.Common">
<item name="android:background">@color/common_bg</item>
</style>
<style name="MatchMatch.Horizontal">
<item name="android:orientation">horizontal</item>
</style>
<style name="MatchAuto.Vertical">
<item name="android:orientation">vertical</item>
</style>
<style name="MatchAuto.Horizontal">
<item name="android:orientation">horizontal</item>
</style>
<style name="AutoMatch.Vertical">
<item name="android:orientation">vertical</item>
</style>
<style name="AutoMatch.Horizontal">
<item name="android:orientation">horizontal</item>
</style>
<style name="WrapAuto.Vertical">
<item name="android:orientation">vertical</item>
</style>
<style name="WrapAuto.Horizontal">
<item name="android:orientation">horizontal</item>
</style>
<style name="AutoWrap.Vertical">
<item name="android:orientation">vertical</item>
</style>
<style name="AutoWrap.Horizontal">
<item name="android:orientation">horizontal</item>
</style>
<style name="MatchOne">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">1px</item>
</style>
<style name="OneMatch">
<item name="android:layout_width">1px</item>
<item name="android:layout_height">match_parent</item>
</style>
<style name="WeightMatch">
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">match_parent</item>
<item name="android:layout_weight">1</item>
</style>
</resources>
values中styles
//styles.xml
<!-- 主题样式 -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:textSize">@dimen/text_middle_size</item>
<item name="android:windowAnimationStyle">@style/AnimationActivity</item>
</style>
<!-- Window黑色背景主题 -->
<style name="AppTheme.Black" parent="@style/AppTheme">
<item name="android:windowBackground">@color/common_black</item>
</style>
<!--Activity进场。出场动画-->
<style name="AnimationActivity" parent="@android:style/Animation.Activity">
<!--用于设置打开新的Activity并进入新的Activity展示的动画-->
<item name="android:activityOpenEnterAnimation">@anim/slide_in_right</item>
<!--用于设置打开新的Activity并销毁之前的Activity展示的动画-->
<item name="android:activityOpenExitAnimation">@anim/slide_out_left</item>
<!--用于设置关闭当前Activity进入上一个Activity展示的动画-->
<item name="android:activityCloseEnterAnimation">@anim/slide_in_left</item>
<!--用于设置关闭当前Activity时展示的动画-->
<item name="android:activityCloseExitAnimation">@anim/slide_out_right</item>
</style>
<!-- 加载弹框样式 -->
<style name="LightDialog" parent="@android:style/Theme.Dialog">
<item name="android:windowFrame">@null</item>
<!--设置是否浮现在activity之上true|false-->
<item name="android:windowIsFloating">true</item>
<!--是否有遮盖-->
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
</style>
<!-- 加载弹框样式 -->
<style name="LightProgressDialog" parent="LightDialog">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowNoTitle">true</item>
</style>
<!-- 通用列表样式-->
<style name="commonRecyclerView">
<item name="android:scrollbars">none</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">match_parent</item>
<item name="android:overScrollMode">never</item>
</style>
<!-- TabLayout文字样式-->
<style name="TabLayoutTextStyle">
<item name="android:textSize">@dimen/text_big_size</item>
</style>
<!-- TabLayout通用样式-->
<style name="TabsStyle">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="tabIndicatorColor">@color/common_white</item>
<item name="tabBackground">@drawable/tab_selector</item>
<item name="tabTextAppearance">@style/TabLayoutTextStyle</item>
<item name="tabTextColor">@color/text_light_dark</item>
<item name="tabSelectedTextColor">@color/common_white</item>
</style>
<!--横向分隔线-->
<style name="DividerFixedHeight">
<item name="android:background">@color/common_divider</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">@dimen/common_divider_height</item>
</style>
<!-- 竖向分隔线 -->
<style name="DividerFixedWidth">
<item name="android:background">@color/common_divider</item>
<item name="android:layout_width">@dimen/common_divider_width</item>
<item name="android:layout_height">match_parent</item>
</style>
<!-- 竖向分隔线 带上下间距 -->
<style name="DividerFixedWidth.MarginTopBottom" parent="@style/DividerFixedWidth">
<item name="android:layout_marginTop">@dimen/common_margin_middle</item>
<item name="android:layout_marginBottom">@dimen/common_margin_middle</item>
</style>
<!--底部出入动画-->
<style name="AnimBottom" parent="@android:style/Animation">
<item name="android:windowEnterAnimation">@anim/push_bottom_in</item>
<item name="android:windowExitAnimation">@anim/push_bottom_out</item>
</style>
<!-- 横屏按钮样式,带不可用状态 -->
<!-- 按钮样式-->
<style name="FullBtnStyle">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">@color/common_white</item>
<item name="android:background">@drawable/btn_common_selector</item>
<item name="android:padding">@dimen/common_padding_middle</item>
<item name="android:layout_margin">@dimen/common_margin</item>
<item name="android:enabled">false</item>
</style>
常用字体颜色
//colors.xml
<color name="colorAccent">#3d3d3d</color>
<color name="colorPrimary">#03a9f4</color>
<color name="colorPrimaryDark">#03a9f4</color>
<color name="common_bg">#f5f5f5</color>
<color name="common_black">#000000</color>
<color name="common_blue">#03a9f4</color>
<color name="common_blue_dark">#0288d1</color>
<color name="common_blue_light">#039be5</color>
<color name="common_disable">#d9d9d9</color>
<color name="common_divider">#d4d4d4</color>
<color name="common_gray">#dddddd</color>
<color name="common_purple">#d500f9</color>
<color name="common_red">#f11919</color>
<color name="common_white">#ffffff</color>
<color name="common_yellow">#fe9c2f</color>
<color name="text_dark">#999999</color>
<color name="text_light_dark">#333333</color>
<color name="text_normal">#666666</color>
<color name="transparent">#00000000</color>
常用dimens
//dimens.xml
<dimen name="common_divider_height">1px</dimen>
<dimen name="common_divider_width">1px</dimen>
<dimen name="common_header_bar_height">50dp</dimen>
<dimen name="common_icon_height">60dp</dimen>
<dimen name="common_icon_width">60dp</dimen>
<dimen name="common_line_height">50dp</dimen>
<dimen name="common_margin">15dp</dimen>
<dimen name="common_margin_middle">10dp</dimen>
<dimen name="common_margin_small">5dp</dimen>
<dimen name="common_padding">15dp</dimen>
<dimen name="common_padding_middle">10dp</dimen>
<dimen name="common_padding_small">5dp</dimen>
<dimen name="common_radius">6dp</dimen>
<dimen name="common_border_size">1px</dimen>
<dimen name="text_small_size">12sp</dimen>
<dimen name="text_middle_size">14sp</dimen>
<dimen name="text_big_size">16sp</dimen>
<dimen name="text_large_size">18sp</dimen>