【问题标题】:How would I change the background colour using an if statement from settings?如何使用设置中的 if 语句更改背景颜色?
【发布时间】:2013-03-24 06:24:14
【问题描述】:

我研究了这个问题,发现需要一个 if 语句。 这是xml部分 pref_general.xml

<ListPreference
    android:defaultValue="Red"
    android:entries="@array/entries"
    android:entryValues="@array/values"
    android:key="example_list1"
    android:title="@string/preferencebackground" />

你会在java中放置什么来改变背景颜色。例如。如果设置列表首选项颜色 = 黑色,则 android:background="#000000" 否则,如果列表偏好颜色 = 绿色...等。

【问题讨论】:

  • 使用可绘制选择器
  • 你是问if-condition怎么写还是if-body里面放什么?
  • if-body 中放什么

标签: java android xml if-statement settings


【解决方案1】:

你会在java中放置什么来改变背景颜色?

你的意思是如何在运行时设置背景颜色?

如果你想改变视图的背景颜色,你可以这样做

View v; // the view you want to change the color...you can findViewById
v.setBackgroundColor(Color.GREEN); 

要更改整个活动的颜色,请参阅How to set background color of an Activity to white programmatically?

或者如果您想在运行时更改整个主题,请尝试How to change current Theme at runtime in Android

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-13
    • 1970-01-01
    • 1970-01-01
    • 2017-07-28
    • 2011-11-11
    相关资源
    最近更新 更多