When it comes to the theme color of the one-click Switch app, it's also possible to continue to talk about how to implement some of the app's icons to change the color of the icon as you move the theme color of the app. For example, the application of the first page of some fixed display icon, or a single box and check box icon, there are some function button icons and so on. The following is the same as the usual, first (there is a picture of the truth there is wood there?) )
You can see that the icon selected below will also immediately follow the theme color of the app when you click on the icon below and then switch to the applicable theme color. The implementation of this function is also very simple, do not need to put each color of the icon to prepare a set of enough. But the color of this set of icons needs to be white. It is then also processed using a subclass of the Colorfilter color filter lightingcolorfilter The light color filter . The relevant code is posted below.
1. Custom Colorimageview
Import Android.content.context;import Android.graphics.lightingcolorfilter;import Android.util.AttributeSet; Import Android.widget.imageview;import Com.qiulong.changedmotivecolortest.mode.colormanager;import Com.qiulong.changedmotivecolortest.mode.oncolorchangedlistener;public class Colorimageview extends ImageView Implements Oncolorchangedlistener {private int color;private boolean iscolorenabled = True;public Colorimageview ( Context context, AttributeSet attrs, int defstyleattr) {Super (context, attrs, defstyleattr);} Public Colorimageview (context context, AttributeSet Attrs) {Super (context, attrs);} Public Colorimageview (Context context) {super (context);} @Overridepublic void oncolorchanged (int color) {if (This.color = = color) {return;} This.color = Color;if (iscolorenabled) {setcolorfilter (new Lightingcolorfilter (color, 1));}} public void Setcolorfilterenabled (Boolean iscolorenabled) {if (this.iscolorenabled = = iscolorenabled) {return;} this.iscolorenabled = Iscolorenabled;if (iscolorenabled) {Setcolorfilter (new Lightingcolorfilter (color, 1));} else {setcolorfilter (null);}} @Overrideprotected void Onattachedtowindow () {colormanager.getinstance (). AddListener (this); Super.onattachedtowindow ();} @Overrideprotected void Ondetachedfromwindow () {colormanager.getinstance (). RemoveListener (this); Super.ondetachedfromwindow ();}}
2. Application theme Activity class: Motiveactivity
Import Android.app.activity;import Android.os.bundle;import Android.view.view;import Android.view.view.onclicklistener;import Com.qiulong.changedmotivecolortest.r;import Com.qiulong.changedmotivecolortest.mode.colormanager;import Com.qiulong.changedmotivecolortest.view.colorimageview;public class Motiveactivity extends Activity implements Onclicklistener {Private final int[] layouts = {r.id.skin_01, r.id.skin_02, R.id.skin_03,r.id.skin_04, r.id.skin_05};p R Ivate Colorimageview mselected, mchecked, mdelete; @Overrideprotected void OnCreate (Bundle savedinstancestate) { Super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_motive); Initview ();} private void Initview () {Findviewbyid (r.id.motive_back). Setonclicklistener (New Onclicklistener () {@Overridepublic void OnClick (View v) {finish ();}}); int colorarr[] = colormanager.getinstance (). Getskincolor (this), for (int i = 0; i < layouts.length; i++) {View view = Fi Ndviewbyid (Layouts[i]); View color = View.findviewbyid (r.id.motive_itEm_color); View selected = View.findviewbyid (r.id.motive_item_selected); Color.setbackgroundcolor (Colorarr[i]); if (ColorArr[i] = = MyApplication.mPreference.getSkinColorValue ()) {selected.setvisibility (view.visible);} Color.setonclicklistener (New Onskincolorclicklistener (i)); mselected = (Colorimageview) Findviewbyid (r.id.motive_selected); mchecked = (Colorimageview) findViewById (R.id.motive _checked); mdelete = (Colorimageview) Findviewbyid (r.id.motive_delete); setcolorimageviewenabled (mSelected, MyApplication.mPreference.getSelectedEnabled ()); Setcolorimageviewenabled (mchecked, MyApplication.mPreference.getCheckedEnabled ()); Setcolorimageviewenabled (Mdelete, MyApplication.mPreference.getDeleteEnabled ()); Mselected.setonclicklistener (this); Mchecked.setonclicklistener ( this); Mdelete.setonclicklistener (this);} Class Onskincolorclicklistener implements Onclicklistener {private int position;public onskincolorclicklistener (int Position) {this.position = position;} @Overridepublic void OnClick (View v) {for(int i = 0; i < layouts.length; i++) {View view = Findviewbyid (Layouts[i]); View selected = View.findviewbyid (r.id.motive_item_selected); selected.setvisibility (i = = position?) View.VISIBLE:View.GONE); Colormanager.getinstance (). Setskincolor (Motiveactivity.this,position);}} @Overridepublic void OnClick (View v) {switch (V.getid ()) {case R.id.motive_selected:boolean isSelected = Mselected.isselected ()? False:true;setcolorimageviewenabled (mselected, isSelected); MyApplication.mPreference.setSelectedEnabled (isSelected); break;case R.id.motive_checked:boolean isChecked = Mchecked.isselected ()? False:true;setcolorimageviewenabled (mchecked, isChecked); MyApplication.mPreference.setCheckedEnabled (isChecked); break;case R.id.motive_delete:boolean isdelete = Mdelete.isselected ()? False:true;setcolorimageviewenabled (Mdelete, isdelete); MyApplication.mPreference.setDeleteEnabled (isdelete); break;}} private void setcolorimageviewenabled (Colorimageview imageview,boolean isenabled) {Imageview.setSelected (isenabled); imageview.setcolorfilterenabled (isenabled);}}
The above content is only for the reference and the study, if has the wrong place to welcome the correction and the discussion, thanks!
Download source please poke here: http://download.csdn.net/detail/baidu_23478311/9515416
Android implements one-click Switch app theme colors (ii)