自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

值得一看:Android給應(yīng)用定制皮膚

移動開發(fā) Android
皮膚也就是相關(guān)的資源文件單獨放置在某個工程中,一種皮膚一個工程文件.一個工程包括N多的資源文件,多個工程間資源的關(guān)系是,文件名,資源ID等完全一樣.不同的可能是圖片資源,style等的設(shè)置不一樣.

在實現(xiàn)程序功能的同時,如果能讓程序界面更加美觀,有錦上添花之妙.

先說思路:

1)皮膚也就是相關(guān)的資源文件單獨放置在某個工程中,一種皮膚一個工程文件.一個工程包括N多的資源文件,多個工程間資源的關(guān)系是,文件名,資源ID等完全一樣.不同的可能是圖片資源,style等的設(shè)置不一樣.

皮膚工程在AndroidManifest.xml中配置android:sharedUserId="com.eric.skinmain".

表明允許com.eric.skinmain訪問本工程中的資源文件. com.eric.skinmain是主項目的包名

3)主項目通過 this.createPackageContext("com.eric.blackskin",Context.CONTEXT_IGNORE_SECURITY);

獲取到com.eric.blackskin對應(yīng)的Context,然后通過返回的context對象就可以訪問到com.eric.blackskin中的任何資源,如同訪問自身的資源一樣.

注:記得先安裝皮膚工程對應(yīng)的apk文件.

  1. public class main extends Activity { 
  2.         /** Called when the activity is first created. */ 
  3.         private LinearLayout showBg; 
  4.         private Button btn; 
  5.         private Context green_skin_Context = null
  6.         private Context black_skin_Context = null
  7.         int flag = 0
  8.  
  9.         @Override 
  10.         public void onCreate(Bundle savedInstanceState) { 
  11.                 super.onCreate(savedInstanceState); 
  12.                 setContentView(R.layout.main); 
  13.                 showBg = (LinearLayout) findViewById(R.id.linear_layout_1); 
  14.                 try { 
  15.                         green_skin_Context = this.createPackageContext( 
  16.                                         "com.eric.greenskin", Context.CONTEXT_IGNORE_SECURITY); 
  17.                 } catch (NameNotFoundException e) { 
  18.                         e.printStackTrace(); 
  19.                 } 
  20.                 try { 
  21.                         black_skin_Context = this.createPackageContext( 
  22.                                         "com.eric.blackskin", Context.CONTEXT_IGNORE_SECURITY); 
  23.                 } catch (NameNotFoundException e) { 
  24.                         e.printStackTrace(); 
  25.                 } 
  26.                 btn = (Button) findViewById(R.id.btn_change_skin); 
  27.                 btn.setOnClickListener(new OnClickListener() { 
  28.                         @Override 
  29.                         public void onClick(View v) { 
  30.                                 if (flag == 0) { 
  31.                                         showBg.setBackgroundDrawable(green_skin_Context 
  32.                                                         .getResources().getDrawable(R.drawable.bg)); 
  33.                                         btn.setBackgroundDrawable(green_skin_Context 
  34.                                                         .getResources().getDrawable(R.drawable.btn_normal)); 
  35.                                          
  36.                                         flag = 1
  37.                                 } else if (flag == 1) { 
  38.                                         showBg.setBackgroundDrawable(black_skin_Context 
  39.                                                         .getResources().getDrawable(R.drawable.bg)); 
  40.                                         btn.setBackgroundDrawable(black_skin_Context 
  41.                                                         .getResources().getDrawable(R.drawable.btn_normal)); 
  42.                                         flag = 0
  43.                                 } 
  44.                         } 
  45.                 }); 
  46.         } 

 

責任編輯:閆佳明 來源: oschina
相關(guān)推薦

2015-07-30 14:20:27

面試攻略

2020-10-18 17:05:43

緩存設(shè)計架構(gòu)

2022-07-29 20:44:06

算力芯片數(shù)字化

2019-05-24 10:29:29

華為咨詢

2015-03-17 10:41:36

2019-10-17 17:45:02

判斷瀏覽器前端

2012-07-24 09:29:33

黑帽大會

2019-01-13 16:18:25

云計算多云部署Kubernetes

2011-04-20 14:48:56

掃描儀

2015-12-02 09:59:14

2019-03-26 09:20:12

蘋果 iOS系統(tǒng)

2022-11-30 14:33:51

網(wǎng)絡(luò)安全安全技術(shù)

2013-07-18 13:18:12

2019-05-23 10:46:53

深度學習代碼算法

2017-01-05 10:43:53

Liunx

2019-08-27 09:03:13

工具插件開發(fā)

2020-12-02 19:09:24

開源源代碼文件

2023-08-08 11:46:36

2020-12-21 09:32:49

開發(fā)設(shè)計UI

2022-06-09 15:45:42

函數(shù)梯度下降
點贊
收藏

51CTO技術(shù)棧公眾號