Skin replacement for Android applications and systems-1

Source: Internet
Author: User

I went to the android development lecture held by csdn yesterday and talked about how to change the application skin and system skin. Here is a summary.

Application skin replacement:

1. Build skin resources into applications. This method is rigid, that is, when the application is released, it determines what skin is available. If you want to release a new skin, you need to release the application again. In addition, placing all skin in the application will make the application installation package relatively large.

2. download the file. That is, the resource file of the skin is not stored in the resource file, but is downloaded by the program after the user selects a skin.

The resource file can be divided into two types, one is a .apk type resource file. The principle of this method is: if the Android: shareduserid attributes of different Android applications are the same, the applications can share resource files. Example:

Create two projects: testskin1 and testskin2. Testskin1 is the main program by default, and testskin2 is the skin resource. There is a button in testskin1, and resources in testskin2 need to be used as the background.

The androidmanifest. xml file of testskin1 is modified as follows:

<?xml version="1.0"encoding="utf-8"?><manifestxmlns:android="http://schemas.android.com/apk/res/android"     package="com.mainskin"     android:versionCode="1"     android:versionName="1.0"     android:sharedUserId="com.test.skin">   <application android:icon="@drawable/icon" android:label="@string/app_name">       <activity android:name=".TestSkin1"                 android:label="@string/app_name">           <intent-filter>                <actionandroid:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER"/>           </intent-filter>       </activity>    </application>  </manifest>

The androidmanifest. xml file of testskin2 is modified as follows:

<?xml version="1.0"encoding="utf-8"?><manifestxmlns:android="http://schemas.android.com/apk/res/android"     package="com.myskin"     android:versionCode="1"     android:versionName="1.0"     android:sharedUserId="com.test.skin">   <application android:icon="@drawable/icon" android:label="@string/app_name">       <activity android:name=".TestSkin2"                 android:label="@string/app_name">           <intent-filter>                <actionandroid:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER"/>           </intent-filter>       </activity>    </application>  </manifest>

The Declaration of the button in the activity of testskin1:

ContextfriendContext=null;                   try{                            friendContext= this.createPackageContext("com.myskin",  Context.CONTEXT_IGNORE_SECURITY);                   }catch (NameNotFoundException e) {                            //TODO Auto-generated catch block                            e.printStackTrace();                   }       Drawable aa=friendContext.getResources().getDrawable(R.drawable.icon);       Button button=(Button)findViewById(R.id.button1);       button.setBackgroundDrawable(aa);

Place two images with the same name as the icon under the drawable of the two projects, but the image content is different.

The second method is to use the. ZIP file to save the resource file. After the software downloads the. Zip package, it decompress it to a certain location, and then access the resources in the program according to the location. This method requires manual maintenance of the resource path in the program, which is inconvenient.

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.