android在代碼中四種設定控制項背景顏色的方法(包括RGB)

來源:互聯網
上載者:User

 

TextView tText=(TextView) findViewById(R.id.textv_name);    //第1種:    tText.setTextColor(android.graphics.Color.RED);//系統內建的顏色類    // 第2種:    tText.setTextColor(0xffff00ff);//0xffff00ff是int類型的資料,分組一下0x|ff|ff00ff,0x是代表顏色整數的標記,ff是表示透明度,ff00ff表示顏色,注意:這裡ffff00ff必須是8個的顏色表示,不接受ff00ff這種6個的顏色表示。         //第3種:    tText.setTextColor(android.graphics.Color.parseColor(#87CEFA)) ; //還是利用Color類;    //第4種:    tText.setTextColor(this.getResources().getColor(R.color.red));            /*通過獲得資源檔進行設定。根據不同的情況R.color.red也可以是R.string.red或者R.drawable.red,     * 當然前提是需要在相應的設定檔裡做相應的配置,如(xml 標籤):     *      * #FF0000        #FF0000        #FF0000*/

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.