Android开源:Android-skin-support - 一款用心去做的Android 换肤框架
felixup
8年前
<h2>介绍</h2> <p>Github地址: https://github.com/ximsfei/Android-skin-support</p> <p>Android-skin-support: 一款用心去做的Android 换肤框架, 极低的学习成本, 极好的用户体验.</p> <p>重要的事情说三遍:</p> <p>只需要两行代码, 就可以实现换肤, 你值得拥有!!! </p> <p>只需要两行代码, 就可以实现换肤, 你值得拥有!!! </p> <p>只需要两行代码, 就可以实现换肤, 你值得拥有!!!</p> <p>第一行: 在Application的onCreate中初始化</p> <p>SkinCompatManager.init( this ).loadSkin();</p> <p>第二行: 继承自SkinCompatActivity</p> <p>public class BaseActivity extends SkinCompatActivity { }</p> <p>就这么简单, 你的APK已经拥有了强大的换肤功能.</p> <p>skin-app // 换肤demo app</p> <p>skin-night // 换肤demo 夜间模式 </p> <p>skin-support // 换肤框架, 基础控件支持 </p> <p>skin-support-design // 换肤框架, Material Design 支持</p> <h2>最佳实践</h2> <p>仿网易云音乐皮肤切换(https://github.com/ximsfei/Skin-Demo)</p> <p>下载(https://github.com/ximsfei/Res/blob/master/skin-demo/app-debug.apk)</p> <p style="text-align:center"><img src="https://simg.open-open.com/show/e4c5ad13ad39bddee76c1787d84fc2bb.jpg"> <img src="https://simg.open-open.com/show/3ddad5da789e398f628ad2db875ceeb8.png"> <img src="https://simg.open-open.com/show/01b4649294a72463619bce2e037c26cc.png"> <img src="https://simg.open-open.com/show/419564ff1f26dd2e946dd7d338723c05.jpg"> <img src="https://simg.open-open.com/show/e11ebfbdb93a5c49c61f64ed6627a678.png"> <img src="https://simg.open-open.com/show/ec2a8224dce9d35afa180066b0fb3223.png"> <img src="https://simg.open-open.com/show/b12b998ea6520729f0e2e36948f9421b.jpg"> <img src="https://simg.open-open.com/show/f38986faff262c10a42af199337cbad9.png"> <img src="https://simg.open-open.com/show/5baebb6b61ced7a9d2eab13b2fe3b55b.png"></p> <h3>目前支持:</h3> <ul> <li> <p>支持Android 4.x, 5.x, 6.x, 7.x</p> </li> <li> <p>支持自定义View换肤</p> </li> <li> <p>skin-support: appcompat-v7 支持</p> <ul> <li> <p>View</p> </li> <li> <p>Button</p> </li> <li> <p>CheckBox</p> </li> <li> <p>EditText</p> </li> <li> <p>TextView</p> </li> <li> <p>ImageView</p> </li> <li> <p>ImageButton</p> </li> <li> <p>RadioButton</p> </li> <li> <p>FrameLayout</p> </li> <li> <p>LinearLayout</p> </li> <li> <p>RelativeLayout</p> </li> <li> <p>CheckedTextView</p> </li> <li> <p>AutoCompleteTextView</p> </li> <li> <p>MultiAutoCompleteTextView</p> </li> <li> <p>android.support.v7.widget.Toolbar</p> </li> </ul> </li> <li> <p>skin-support-design: material design 支持</p> <ul> <li> <p>TabLayout</p> </li> <li> <p>AppBarLayout</p> </li> <li> <p>NavigationView</p> </li> </ul> </li> </ul> <h2>git clone https://github.com/ximsfei/Android-skin-support.git</h2> <p>选择需要的module依赖:</p> <p>// aar dependencies { compile(name: 'skin-support-release', ext: 'aar') // Android 基础控件, 及V7包中的一些控件 compile(name: 'skin-support-design-release', ext: 'aar') // Android support design包中的一些控件 }</p> <p>dependencies {</p> <p>或者</p> <p>compile project(':skin-support') compile project(':skin-support-design') }</p> <p>或者</p> <p>// 可以打开调试日志 dependencies { releaseCompile project(path: ':skin-support', configuration: 'release') debugCompile project(path: ':skin-support', configuration: 'debug') releaseCompile project(path: ':skin-support-design', configuration: 'release') debugCompile project(path: ':skin-support-design', configuration: 'debug') }</p> <h3>初始化:</h3> <p>在Application的onCreate中初始化</p> <p>@Override public void onCreate () { </p> <p>super .onCreate(); SkinCompatManager.init( this ).loadSkin(); </p> <p>// 应用启动加载当前(保存在SharedPreferences中)皮肤库</p> <p>}</p> <p>继承SkinCompatActivity</p> <p>让所有需要换肤的Activity继承自 skin.support.app.SkinCompatActivity .</p> <p>public class BaseActivity extends SkinCompatActivity { }</p> <p>加载插件皮肤库</p> <p>// 指定皮肤插件, 并且监听加载状态</p> <p>SkinCompatManager.getInstance().loadSkin( "new.skin" );</p> <p>// 恢复应用默认皮肤 SkinCompatManager.getInstance().restoreDefaultTheme();</p> <p>自定义View换肤</p> <p>要点:</p> <ol> <li> <p>实现SkinCompatSupportable接口</p> </li> <li> <p>在构造方法中解析出需要换肤的resId</p> </li> <li> <p>在applySkin方法中实现换肤</p> </li> </ol> <p>实现:</p> <ol> <li> <p>自定义View可以直接继承自SkinCompatView, SkinCompatLinearLayout等已有控件</p> <p>eg: CustomTextView</p> </li> <li> <p>不想继承自已有控件</p> <p>eg: CustomTextView2</p> </li> <li> <p>需要换肤自定义属性</p> <p>// 需要换肤AutoCompleteTextView的R.attr.popupBackground属性</p> <p>eg: SkinCompatAutoCompleteTextView</p> </li> <li> <p>需要使用第三方库控件怎么办</p> <p>// 需要使用https://github.com/hdodenhof/CircleImageView 控件, 并且要支持换肤</p> <p>eg: CustomCircleImageView</p> </li> </ol> <h3>制作皮肤插件:</h3> <p>新建Android application工程</p> <p>将需要换肤的资源放到res目录下(同名资源)</p> <p>打包生成apk, 即为皮肤包</p> <p> </p> <p> </p> <p> </p>