2010-08-13 67 views
0

我在找到一種方法來使用XML填充具有SharedPreference值的TextView的方法時遇到問題。 有沒有辦法像字符串資源一樣引用首選項。 喜歡的東西從XML獲取SharedPreference

的TextView的android:文本=「@偏好/名稱」

回答

1

嗨弗蘭克我不認爲這將有可能你必須得到充分利用您的XML,然後設置爲您的TextView偏好。

 SharedPreferences prefs; 


    prefs = PreferenceManager.getDefaultSharedPreferences(this); 
    String username = prefs.getString("username", ""); 

    TextView txtname = (TextView) findViewById(R.id.name); 
    txtname.setText(username);