Android應用換膚

來源:互聯網
上載者:User

SharedUserid 
擁有同一個User id的多個APK可以配置成運行在同一個進程中,所以預設就是可以互相訪問任意資料。也可以配置成運行成不同的進程,同時可以訪問其他APK的資料目錄下的資料庫和檔案,就像訪問本程式的資料一樣。 

哈哈,這個就是我要找的東西,馬上開始實驗。 

工程1(主工程) 
只有1個畫面,包含1個為了測試用的button 
AndroidManifest.xml 

Java代碼:

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

MainActivity

@Override<br />public void onCreate(Bundle savedInstanceState) {<br /> super.onCreate(savedInstanceState);<br /> setContentView(R.layout.main); </p><p> Context friendContext = null; </p><p> try {<br /> friendContext = this.createPackageContext(<br /> "com.test.android.skin.myskin",<br /> Context.CONTEXT_IGNORE_SECURITY);<br /> } catch (NameNotFoundException e) {<br /> e.printStackTrace();<br /> } </p><p> Button btn = (Button) findViewById(R.id.btn);<br /> btn.setBackgroundDrawable(friendContext.getResources().getDrawable(<br /> R.drawable.btn_background));<br />}  

drawable下放一張名為btn_background.pnd的圖片 

工程2(皮膚工程) 
AndroidManifest.xml 

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

drawable下也放一張名為btn_background.png的圖片(換成xml檔案就可以實現不同狀態不同圖片的功能) 


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.