【问题标题】:Is there a way to dynamically change the preference screen font color?有没有办法动态更改首选项屏幕字体颜色?
【发布时间】:2012-02-20 19:12:19
【问题描述】:

This 非常适合静态地做一次。

但是,如果我有字体颜色偏好,并且我希望偏好屏幕本身根据它更新呢?

【问题讨论】:

    标签: android


    【解决方案1】:

    使用来自this 答案的信息,您可以尝试使用SpannableString 对象并以这种方式设置颜色。该答案的示例:

    Spannable summary = new SpannableString ("Currently This Color");
    summary.setSpan( new ForgroundColorSpan(color), 0, summary.length(), 0 );
    preference.setSummary(summary);
    

    【讨论】:

    • 我的错误。这对我有很大帮助。我的颜色不是颜色int而是资源int,我一开始没有转换,应该用new ForegroundColorSpan(getResources().getColor(android.R.color.holo_red_dark))
    【解决方案2】:

    看看我对此的回答:Android PreferenceScreen title in two lines

    添加这个:

    if (textView != null) {
        textView.setTextColor(textView.getContext().getResources().getColor(R.color.blue));
    }
    

    【讨论】:

      猜你喜欢
      • 2020-06-15
      • 2020-08-01
      • 1970-01-01
      • 2020-08-05
      • 1970-01-01
      • 1970-01-01
      • 2020-07-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多