最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【记录】Android中自定义ActionBar的背景色等样式style

Android crifan 4480浏览 0评论

【背景】

Android中想要去自定义ActionBar的背景色等样式。

【折腾过程】

1.自己找代码,发现对应的配置的地方了:

AndroidManifest.xml

    <application
        android:theme="@style/AppTheme" >

找到

/res/values/styles.xml

中的:

    <style name="AppTheme" parent="@android:style/Theme.Holo.Light">
        <item name="android:actionModeBackground">@drawable/cab_background_top_xxxstyle</item>
    </style>

对应的cab_background_top_xxxstyle是个图片,是深蓝色的,所以效果是:

actionbar dark blue effect by png drawable

2.而此处,由于背景色不是通过的Color去定义的,所以无法很简单的通过直接改color而达到改变背景色的效果。

所以只能去考虑换一个这个drawable的png图片。

但是发现该图片时那种9 pitch的,但是自己目前不太懂,不会生成,所以要去研究那个:

【记录】研究Android中的9 patch的图片的原理以及如何去生成对应图片

3.然后看到:

http://jgilfelt.github.io/android-actionbarstylegenerator/

中有帮忙生成actionbar的9patch的图片的,所以去试了试:

Android Action Bar Style Generator effect 1

Android Action Bar Style Generator effect 2

Android Action Bar Style Generator effect 3

Android Action Bar Style Generator effect 4

然后下载到:

actionbar_style_rocksensor.zip

解压后,得到很多对应的文件:

generated actionbar style for rocksensor

 

然后去把所有文件都拷贝到项目中,去试试效果:

newly style using generated 9patch files

效果还不错。

 

【总结】

以后如果想要换整体的ActionBar等主题的话,就可以去利用:

Android Action Bar Style Generator

转载请注明:在路上 » 【记录】Android中自定义ActionBar的背景色等样式style

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
83 queries in 0.170 seconds, using 22.11MB memory