1
我有一個活動,我想根據用戶偏好更改顏色。如何根據用戶偏好更改RelativeLayout顏色?
我在styles.xml創造了許多風格
<style name="Yellow" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">$ffff00</item>
<item name="colorPrimaryDark">#000000</item>
<item name="colorAccent">#ffff00</item>
</style>
<style name="Red" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#ff0000</item>
<item name="colorPrimaryDark">#000000</item>
<item name="colorAccent">#ff0000</item>
</style>
這是確定了我的工具欄,等等。問題是,我想改變一個RelativeLayout的背景選擇colorPrimary顏色。它獲取我的默認AppTheme顏色。
我活動的OnCreate:
setTheme(R.style.Yellow);
myactivity.xml
<RelativeLayout
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/colorPrimary">
如何設置myactivity基於黃色或紅色的RelativeLayout bkcolor(用戶任選其一)?
非常感謝你! –