Android記錄一個setTextColor常見的一個bug,androidbug

來源:互聯網
上載者:User

Android記錄一個setTextColor常見的一個bug,androidbug

   今天寫代碼 一不小心就犯了個錯誤。仔細檢查才發現,僅記錄一下,防止各位同學犯同樣的錯誤哦

代碼如下:

  

remote.setTextColor(summaryId, R.color.news_have_read);

如上,代碼無論如何都不能正常顯示顏色。只好換成如下代碼:

remote.setTextColor(summaryId,0xfdfdfdfd);

總不能寫顏色值多麻煩。。還是寫的color.xml中吧。

最後才發現應該這樣寫才最對。

remote.setTextColor(summaryId, mContext.getResources().getColor(R.color.news_is_have_read));

在remote.setTextColor(summaryId, R.color.news_have_read);這段代碼中,顯示的是R.color.news_have_read通過eclipse產生的int值並不是真正的顏色值,必須通過mContext.getResources().getColor將真正的16進位顏色值#255#255#255#255值取得到才可以。


Android中要顯示一個表格,是這樣的:

TableLayout t;TableRow row;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);t = (TableLayout) findViewById(R.id.t);int z[] = {4,3,5};ArrayList<View> v = new ArrayList<View>();for (int x = 0; x < 3; x++) {row = new TableRow(this);for (int i = 0; i < z[x]; i++) {TextView t1 = new TextView(this);t1.setText("32323232");t1.setTextColor(Color.BLACK);row.addView(t1);}t.addView(row);}}
 
android的開發,在環境裡的res/Values檔案夾裡沒有一個Color的xml檔案,於是我建立了一個問題就來了

Resources.getColor()看看你的引用路徑對嗎?
android.blog.51cto.com/268543/302529給你推薦一個部落格專門講解資源檔夾的。
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.