框架提供了一种Theme切换的方案,具体原理不清楚,表现如下:
提供N个theme文件夹,把对应的图片和颜色放入这些theme文件夹下的zip压缩格式的包中,则切换theme时,使用的资源会根据theme的切换而切换,如:
/custpack/theme/1/com.android.mms/res/drawable-ldpi/list_selected_holo_light.9.png
/custpack/theme/2/com.android.mms/res/drawable-ldpi/list_selected_holo_light.9.png
/custpack/theme/3/com.android.mms/res/drawable-ldpi/list_selected_holo_light.9.png
/custpack/theme/4/com.android.mms/res/drawable-ldpi/list_selected_holo_light.9.png
/custpack/theme/5/com.android.mms/res/drawable-ldpi/list_selected_holo_light.9.png
/custpack/theme/6/com.android.mms/res/drawable-ldpi/list_selected_holo_light.9.png
PS:com.android.mms为一个zip格式的压缩包,进行zip压缩后,把.zip的后缀名去掉即可。当用户在设置的Theme中切换主题时,模块中使用的list_selected_holo_light.9.png图片会变化。
UE提供的.9.png图片,直接放入com.android.mms中,显示总有问题,后来确认是要用aapt工具处理一下,原理目前未知,处理方法如下:
aapt s -i inputfile -o outputfile
PS:inputfile为UE提供的图片,outputfile为可使用的图片
因为UE提供的.9.png图片比较多,这里采用了如下的python来对这些图片进行批处理:
# -*- coding: utf-8 -*-
# It is ok at python-3.3.1rc1.msi installer condition.
# example: aapt s -i inputfile -o outputfile
# D:\AndroidDev\adt-bundle-windows-x86-20130729\sdk\build-tools\android-4.3\aapt.exe s -i E:\98.Temp\ThemeTest\blue_top.9.png -o E:\98.Temp\ThemeTest\blue_top_new.9.png
import os
import re
walk_names = os.walk(r'E:\98.Temp\ThemeTest')
cmd = r'D:\AndroidDev\adt-bundle-windows-x86-20130729\sdk\build-tools\android-4.3\aapt.exe';
for (directory, sub_directorys, file_names) in walk_names:
for name in file_names:
m = re.match(r'(.+)\.9\.png$', name, re.I)
if m:
src = os.path.join(directory, name)
dst = os.path.join(directory, m.group(1)) + '_new.9.png'
tmpCmd = cmd + ' s -v -i ' + src + ' -o ' + dst
print(tmpCmd)
os.system(tmpCmd)