在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