自定义一个Theme

本文介绍了如何在Android中自定义Theme,通过继承Theme.Holo.Light,并设置自定义的list选择背景和ActionBar样式。详细步骤包括创建<style>,定义selector drawable以改变list选择状态,以及定制ActionBar的背景颜色和文字颜色。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. 继承已有Theme(不然写的属性就太多了)
在自己的某个style.xml或者theme.xml中加上
<style name = "Theme_Custom" parent="@*android:style/Theme.Holo.Light">
	<item name = "android:listChoiceBackgroundIndicator">@drawalbe/custom_list_selector_holo_light></item>
	<item name = "android:actionBarStyle">@style/CustomActonbar></item>
</style>
以上自定义list的背景色:custom_list_selector_holo_light

2.实现具体的属性
1). custom_list_selector_holo_light.xml是放在res/drawable/下,可以指定一个随点击或者按下产生不同效果的图片,
<selector xmlns:android=""http://schemas.android.com/apk/res/android">
	<item android:state_pressed="true" android:drawable="@drawable/wind_list_focused"/>
	<item android:state_focused="true"android:state_enable="true" android:drawable="@drawable/wind_list_focused"/>
</selector>
wind_list_focused.9.png就是一张9patch的文件了。


2). @style/CustomActonbar是自己写的style
修改/res/values/style.xml
<style name="WindCustomTitleTextColor" parent="@*android:style/TextAppearance.Holo.Widget.ActionBar.Title">
	<item name = "android:textColor">@*android:color/white</item>
</style>

<style name="WindCustomActionbar" parent="@*android:style/Widget.Holo.Light.ActionBar.Solid">
	<item name = "android:background">@drawalbe/wind_titlebar_background></item>
	<item name = "android:titleTextStyle">@style/WindCustomTitleTextColor></item>
</style>

上面的两个属性是自定义ActionBar的背景色:wind_titlebar_background.png和字体颜:@*android:color/white
wind_titlebar_background.png为ActionBar的背景图片
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值