我想将 SwitchCompat 的app:theme属性值更改为其他值(@style/switchColorStyleBlue)。我怎样才能以编程方式做到这一点?(app:theme 基本上改变了切换的颜色)
<android.support.v7.widget.SwitchCompat
android:id="@+id/switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:theme="@style/switchColorStylePink"/>
我已经尝试过这段代码,但它没有显示适当的结果:
SwitchCompat switchCompat = new SwitchCompat(this);
switchCompat.setId(i);
switchCompat.setSwitchTextAppearance(getApplicationContext(), R.style.switchColorStylePink);
switchCompat.setChecked(false);
containerRelativeLayout.addView(switchCompat);
我想要的是将主题(开关的颜色)从粉红色更改为蓝色或反之亦然。