2013-07-22 47 views

回答

0

要改變LED的顏色: Check this link

對於BATTERY_LOW你會定義一個BroadcastReceiver: Check this link

確定。

首先,在values文件夾中創建一個文件。稱之爲「preference_res.xml」。然後增加以下內容:

<?xml version="1.0" encoding="utf-8"?> 
<resources> 

<string-array 
    name="prefColor"> 
    <item>None</item> 
    <item>Blue</item> 
    <item>Green</item> 
    <item>Yellow</item> 
    <item>Other Color</item> 
</string-array> 
<string-array 
    name="prefColorVal"> 
    <item>-1</item> 
    <item>-2</item> 
    <item>79</item> 
    <item>24</item> 
    <item>25</item> 
    <item>27</item> 
    <item>80</item> 
</string-array> 
</resources> 

(。請注意,prefColorVal項目應參考到你想要的單選按鈕具有值這裏顯示的值是隨機的)

在你preference.xml,添加這樣的事情:

<ListPreference 
    android:dialogTitle="Choose color" 
    android:entries="@array/prefColor" 
    android:entryValues="@array/prefColorVal" 
    android:key="bat_below_15" 
    android:negativeButtonText="Cancel" 
    android:positiveButtonText="Save" 
    android:summary="Choose color when below 15" 
    android:title="Color when below 15" /> 

如果你不知道如何獲得或使用這些值,這裏有一些指點,但你應該google一下東西:

preferences = PreferenceManager.getDefaultSharedPreferences(ctx); 

,並用它來獲得的價值:

preferences.getString("bat_below_15", Blue)); 

希望它能幫助。

+0

那麼,我已經有一個broadcastreceiver ..問題是偏好中的單選按鈕。我想要的東西就像「當電池電量約爲15%時顯示led的顏色」。你可以從對話框中選擇單選按鈕組的顏色..我可以做到嗎? –