Android 如何使用变量作为getResourceId(int-index,int-defValue)中的索引;
我使用以下代码定义背景按钮:Android 如何使用变量作为getResourceId(int-index,int-defValue)中的索引;,android,sharedpreferences,android-resources,Android,Sharedpreferences,Android Resources,我使用以下代码定义背景按钮: TypedArray bottombuttons = res.obtainTypedArray(R.array.bottombuttons ); button0.setBackgroundResource(bottombuttons .getResourceId(index, 1)); 其中index是来自共享活动的变量 int index = themePref.getInt("index", 1); 答案是我必须在onResume()中进行更改,而不是在o
TypedArray bottombuttons = res.obtainTypedArray(R.array.bottombuttons );
button0.setBackgroundResource(bottombuttons .getResourceId(index, 1));
其中index
是来自共享活动的变量
int index = themePref.getInt("index", 1);
答案是我必须在
onResume()
中进行更改,而不是在onCreate()
中进行更改答案是我必须在onResume()
中进行更改,而不是在onCreate()