在android中,getResource()方法可用於獲取在xml文件中聲明的資源。像:Android SET資源文件項目
<resources>
<string name="sample_1">Sample 1</string>
<string name="sample_2">Sample 2</string>
<string name="sample_3">Sample 3</string>
<string name="sample_4">Sample 4</string>
<string name="sample_5">Sample 5</string>
</resources>
,我想sample_1文本類我這樣做:
getString(R.string.sample_1);
因此,獲得的方法是有訪問他們,但這裏是設置方法。我在互聯網上搜索了很多,但沒有找到有用的東西。在運行時通過java設置字符串和顏色資源的方法是什麼。互聯網是充滿例子是這樣的:
TextView ab = findviewbyid(........);
ab.setText("bla bla");
我不想這樣,我想資源文件項中直接更改,如:
setResouces(R.color.primarycolor) to #00000
有沒有像上面的解決方案?
沒有** set **方法,因爲資源**不能寫入**。您可以使用其他方法,例如將虛擬機保存到SharedPReferences或數據庫中。或者存儲中的其他文本或xml文件。 –
我認爲沒有設定方法,沒有必要。你爲什麼需要這個?描述您的使用案例,並且可能還有針對您的問題的另一個解決方案。 –
對不起。不可能。 – Rohit5k2