您的位置:首页 > 移动开发 > Android开发

[置顶] Android--(14)--通过安卓选择器来修改actionbar的样式与字体样式

2017-10-21 13:52 537 查看
一.修改actionbar样式的基本步骤:

1.首先在drawable文件夹下新建一个选择文件select_style.xml备用,代码如下:

selector的常用属性:

android:state_selected : 表示是否为选中状态

android:state_pressed : 表示是否为点击状态

然后根据不同的状态来设定不懂得效果

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- 未选中未点击 -->
<item  android:state_selected="false"
android:state_pressed="false"
android:drawable="@drawable/top_3" />
<!-- 选中未点击 -->
<item android:state_selected="true"
android:state_pressed="false"
android:drawable="@drawable/top_2" />
</selector>


2.重写actionBarTabStyle属性,然后将它指向一个新建的Tab样式;并在此样式中将background属性指定为刚创建的选择样式;代码如下:

<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarTabStyle">@style/actionBarStyle</item>
</style>

<!-- 创建的style样式 -->
<style name="actionBarStyle" parent="@android:style/Widget.Holo.ActionBar.TabView">
<item name="android:background">@drawable/select_style</item>
</style>

</resources>


到此样式设置就完成啦;

二.设置字体颜色

重写android:actionBarTabTextStyle属性

将style修改为如下方式:

<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarTabTextStyle">@
ae39
style/actionTextstyle</item>

<item name="android:actionBarTabStyle">@style/actionBarStyle</item>
</style>
<!-- 设置标题Tab的字体样式 -->
<style name="actionTextstyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">@drawable/select_text</item>
<item name="android:textSize">18sp</item>
</style>

<!-- 创建的style样式 -->
<style name="actionBarStyle" parent="@android:style/Widget.Holo.ActionBar.TabView">
<item name="android:background">@drawable/select_style</item>
</style>

</resources>


没啥技术含量,重写某一属性就行

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐