App skinning ideas and ListView item click

Source: Internet
Author: User

Haven't written a blog for a long time, looking at more than two articles per month more than three of the rhythm, feel that they have not been saved ~ plan to two articles each week, the pressure is big said. Ya minute fly butterfly

For a new company .

Now in the app is simply thriller, is a NetEase + Weibo + Baidu map + enhanced version, one months can make a demo, I really give the present colleague next kneeling and not reliable party a Orz

To get to the point, now in the app needs to achieve the effect of click to change skin, similar to NetEase cloud music of red and black skin switching effect (of course, here is simplified, the current in the app only the title bar and sidebar skin color needs to switch, and the night day mode switch is not the same, that complex). First of all, the idea can be implemented with Android Sharedpreferences, set the default red skin storage 0, set the black skin storage 1.

The following begins the code:

I have written a tool class that can be used to determine the current skin pattern and to implement a toggle

 //Tool class public class skinmode{private context context;        Private Sharedpreferences Skinmode;        Public Skinmode (Context context) {Skinmode = Context.getsharedpreferences (); }//Get skin mode, 0 for default red, 1 for black public int getskinmode () {return Skinmode.getsharedpreferenc        ES ("Skinmode", 0);        }//Set skin mode public void Setskinmode (int skinmode) {skinmode.put ("Skinmode", Skinmode);                public void Setviewskinmode (View view,int skinmode) {if (0==skinmode)   {Setskinmode (Skinmode);                mode switch View.setbackgroundcolor (color.red);//Set Color} else if (1==skinmode)                    {Setskinmode (Skinmode);                View.setbackgroundcolor (Corlor.black); }        }}

Day and night mode switch is also involved in Font transformation, control transparency and so on, more complex, this I can not do ~

Another problem is that when you click on the GridView item, it's easier to implement a checkbox-like radio effect.

The code is implemented as follows:

gridview.setOnItemClickListener(new OnItemClickListener( AdapterView view,View view,int position,long id){        for(int i=0;i<gridview.getChildCount();i++)        {            TextView tv = (TextView)gridview.getChildAt(i);            tv.setBackroundColor(color.Black);  // 默认是黑色        }        view.setBackgroundColor(color.Red);//点击后是红色}

)

Thats all

App skinning ideas and ListView item click

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.