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.