我如何在 getResourceId(int index, int defValue); 中使用变量作为索引?
how can i use a variable as index in getResourceId(int index, int defValue);
我使用下面的代码来定义按钮背景:
TypedArray bottombuttons = res.obtainTypedArray(R.array.bottombuttons );
button0.setBackgroundResource(bottombuttons .getResourceId(index, 1));
其中 index
是来自共享的变量 activity
int index = themePref.getInt("index", 1);
答案是我必须在 onResume()
而不是 onCreate()
中进行更改
我使用下面的代码来定义按钮背景:
TypedArray bottombuttons = res.obtainTypedArray(R.array.bottombuttons );
button0.setBackgroundResource(bottombuttons .getResourceId(index, 1));
其中 index
是来自共享的变量 activity
int index = themePref.getInt("index", 1);
答案是我必须在 onResume()
而不是 onCreate()