我完全被卡住(如何设置几个背景的一个主题
UPD,它可以是通过施加一个主题来设置不同的视图不同的背景(或其他属性)?
如何应该针对不同主题的不同风格应用不同风格? 简而言之,我想根据一天中的时间更改主题,以相应地更改视图的属性(颜色,背景等)
Profi,任何提示将会大大增加。
我完全被卡住(如何设置几个背景的一个主题
UPD,它可以是通过施加一个主题来设置不同的视图不同的背景(或其他属性)?
如何应该针对不同主题的不同风格应用不同风格? 简而言之,我想根据一天中的时间更改主题,以相应地更改视图的属性(颜色,背景等)
Profi,任何提示将会大大增加。
最后,我已经找到了一个解决方案,它是经过我自己的心脏!我怀疑这些硬编码方法不是非常灵活的解决方案,需要多路复用代码取决于实现的主题数量。 对于thouse谁面临着同样的任务请看看在link
宣告属性为风格参考使用:
<declare-styleable name="CustomThemeViews"> <attr name="myViewStyle" format="reference"/> </declare-styleable> Define styles for each theme: <style name="myViewStyleTheme01"> <item name="android:background">#f00</item> </style> <style name="myViewStyleTheme02"> <item name="android:background">#0f0</item> </style> Define themes that refer to different styles: <style name="AppTheme" parent="android:Theme.Light"> <item name="myViewStyle">@style/myViewStyleTheme01</item> </style> <style name="AppThemeAlternative" parent="android:Theme.Light"> <item name="myViewStyle">@style/myViewStyleTheme02</item> </style> Use themed styles in layout <ListView style="?attr/myViewStyle" android:layout_width="match_parent" android:layout_height="match_parent" ... Now the style applied to the ListView changes according to the theme applied.
ü应该做的switch语句,如:
int theme;
String color;
switch (theme) {
case 1: color = redandblue;
//code
break;
case 2: color = greenanddark;
//code
break;
case 3: color = redandwhite;
//code
break;
default: color = standard;
//default mean that this will be call when any upper not call
break;
代码意味着UR的喜好颜色的观点
也可以ü如果其他
if(theme == 1){
//code
}else if(theme == 2){
//code
}else if(theme == 3){
//code}
...
为此在最后与配置主题方法
private void configureFirstTheme(){
//code
}
private void configureSecondTheme(){
//code
}
你可以添加构造函数的方法
private void themeSetup(int theme){
//here the switch statement
}
希望你会选择什么
)所以不可能通过附加另一个主题来改变View的属性?“Switchcasing”似乎是一个非常难看的机制。如果有两个以上的主题和大量的自定义视图,它需要大量的手工编码((看起来很可能是 –
),你也可以做if if语句并为你的布局的每个配置制作方法。方法来完成这个任务 – Rodriquez
所以请给我一个正确的方法从“许多”正确地做到这一点,或提供一个链接到资源阅读about.Thx提前 –
请告诉我目前的问题,您都面临着? – Sanoop
这不是一个问题,直到我不知道该怎么做。这是请求帮助。问题很复杂,我既不能制定一个正确的问题,也不能在互联网上找到可理解的东西。 –
我想要的只是改变主题,并获得视图的属性(-s)与另一个值设置。 –