【问题标题】:How can I change the TextView text color on the appwidget?如何更改 appwidget 上的 TextView 文本颜色?
【发布时间】:2020-12-10 15:11:37
【问题描述】:

正如我在标题中提到的,我无法更改 TextView 的颜色。(以编程方式)

我尝试了以下代码,但它不起作用:

views.setTextColor( R.id.txtPtw2Gunes, context.getResources().getColor( R.color.widgetOrange ) );

views.setTextColor( R.id.txtPtw2Aksam, Color.parseColor( "#e4e4e4" ) );

我该如何帮助您做到这一点?

编辑: views.setTextColor( R.id.txtPtw2Gunes, context.getResources().getColor( R.color.widgetOrange ) );

实际上我添加的代码有效,但在模拟器上无效。我在真机上测试时发现它可以正常工作。

主题可能被锁定。

【问题讨论】:

    标签: java android android-studio android-appwidget textcolor


    【解决方案1】:

    也许您可以尝试以下方法:

    ((TextView)findViewById(R.id.txtPtw2Gunes)).setTextColor(getResources().getColor(R.color.widgetOrange));
    

    ((TextView)views.findViewById(R.id.txtPtw2Gunes)).setTextColor(getResources().getColor(R.color.widgetOrange));
    

    【讨论】:

    • 实际上我添加的代码有效,但它在模拟器上无效。当我在真机上测试它时,我发现它可以工作。 views.setTextColor(R.id.txtPtw2Gunes, context.getResources().getColor(R.color.widgetOrange));感谢您的回答。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    相关资源
    最近更新 更多