簡體   English   中英

如何在Android中設置自定義顏色

[英]How to set custom color in android

這是我的res / values / color.xml

 <resources>
    <color name="ColorPrimary">#FF5722</color>
</resources>

這是.java文件

Color color = context.getResources().getColor(R.color.ColorPrimary); //Error
    textView.setTextColor(color);

給我一個錯誤。 必需的android.graphics.Color。 發現int

我該如何處理?

getColor方法返回一個int,但是您嘗試將其存儲在Color對象中。 我建議您只是這樣做:

textView.setTextColor(context.getResources().getColor(R.color.ColorPrimary))

由於setTextColor采用int參數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM