2012-09-27 33 views
3

,我想我的應用程序在不同情況下烙印可用 - 這意味着它必須能夠輕易改變的背景位圖在少數地方,而且還改變了文本資源。應用程序標記

我的計劃是使用的主題和風格,我知道他們可用於切換位圖,但他們會允許我也改變文本在TextViews例如?

是否也可以在風格或主題,以指定文本標識,後來在代碼中動態看了嗎?

[編輯]

經過一番調查,當然文本可以使用樣式取代。應用程序品牌的另一個問題是需要更改軟件包名稱,否則Google Play不會接受我們的品牌應用程序。

[編輯]

經過調查,下面我包括如何添加兩個切換主題,將允許在分別代替活動佈局繪製和文本資源的TextView的小樣。剩下的就是叫setTheme(R.style.The1);或setTheme(R.style.Theme2);在setContentView之前的onCreate中。

<-- attrs.xml /> 
<resources> 
    <attr name="ProductName" format="reference"/>  
    <attr name="ProductBackground" format="integer"/> 
</resources> 

<-- styles.xml /> 
<resources xmlns:android="http://schemas.android.com/apk/res/android"> 
    <style name="Theme1" parent="android:Theme.Light"> 
     <item name="ProductName">@string/s_product_1_name</item> 
     <item name="ProductBackground">@drawable/back_1_vga</item> 
    </style>  
    <style name="Theme2" parent="android:Theme.Light" >   
     <item name="ProductName">@string/s_product_2_name</item> 
     <item name="ProductBackground">@drawable/back_2_vga</item> 
    </style> 
</resources> 

<-- my activity layout /> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="?ProductBackground" 
    > 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_centerVertical="true" 
     tools:context=".MainActivity" 
     android:background="#ff0000" 
     android:text="?ProductName" 
     /> 
</RelativeLayout> 
+0

我有一個愚蠢的答案,可能。我把我的字符串放在... strings.xml中,將其命名爲「品牌」,將我的圖片命名爲「drawable」文件夾,名爲「logo.png」 - 然後更改每個客戶的字符串和圖片誰想要我的應用程序的品牌化版本。 –

+0

@Vyger問題也在於更改軟件包名稱,並將其全部自動化。自從提出這個問題以來,我已經根據自己學習的內容添加了答案。 – marcinj

回答

0

有兩種aproaches讓你的應用程序的不同烙印:

1)劃分應用到多個庫項目,常見的代碼是在讓說common_lib庫項目,以及所有的烙印在單獨的使用common_lib的項目,但更改一些資源,如字符串,一些可繪製的,也包名稱。這是我們在應用程序中選擇的答案。

2)使用gradle這個產品口味:http://developer.android.com/sdk/installing/studio-build.html,我覺得現在應該是首選的解決方案。