欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

android中colors.xml顏色設(shè)置資源文件的方法

 更新時(shí)間:2021年03月23日 09:54:20   作者:你要永遠(yuǎn)相信光z  
這篇文章主要介紹了android中colors.xml顏色設(shè)置資源文件,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

1. 打開(kāi)res目錄下的values文件夾,雙擊打開(kāi)colors.xml文件進(jìn)行編輯

在這里插入圖片描述

上代碼

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <color name="colorPrimary">#008577</color>
  <color name="colorPrimaryDark">#00574B</color>
  <color name="colorAccent">#D81B60</color>
  <color name="color_xml">#ff0000</color>
  <color name="color_java">#0000ff</color>
</resources>

2. 在res目錄下的layout文件夾創(chuàng)建color_layout.xml文件

在這里插入圖片描述

在這里插入圖片描述

下述代碼演示如何在XML文件中訪問(wèn)顏色.

上代碼

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical">
  <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text = "XML文件訪問(wèn)colors資源(紅色)"
    android:id = "@+id/tv3"
    android:textColor="@color/color_xml" />
  <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text = "Java文件訪問(wèn)colors資源(藍(lán)色)"
    android:id = "@+id/tv4" />
</LinearLayout>

上述代碼中@color/color_xml 為XML文件讀取colors.xml文件中名為color_xml的RGB顏色代碼,并將該顏色以 Text View的形式顯示出來(lái)。

3. 在java目錄下的com.example.myapplication包中創(chuàng)建Color_ActivityDemo類

在這里插入圖片描述
在這里插入圖片描述

下述代碼演示如何在Java代碼中訪問(wèn)顏色。

上代碼

package com.example.myapplication;

import android.os.Bundle;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class Color_ActivityDemo extends AppCompatActivity {
  TextView tv4;
  public void onCreate(Bundle saveInstanceState) {
    super.onCreate(saveInstanceState);
    setContentView(R.layout.color_layout);
    tv4 = (TextView) findViewById(R.id.tv4);
    tv4.setTextColor(getResources().getColor(R.color.color_java));
  }
}

上述代碼中g(shù)etResources ().getColor(R.color.color _java)為Java代碼讀取colors.xml文件中名為color_java的 RGB顏色代碼,并將該顏色以TextView的形式顯示出來(lái)。

4. 在AndroidMainfest.xml文件添加Color_ActivityDemo.java的列表

在這里插入圖片描述在這里插入圖片描述

5. 運(yùn)行Color_ActivityDemo.java

在這里插入圖片描述

運(yùn)行結(jié)果

在這里插入圖片描述

到此這篇關(guān)于android中colors.xml顏色設(shè)置資源文件的文章就介紹到這了,更多相關(guān)android中colors.xml顏色內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Android使用Canvas繪制圓形進(jìn)度條效果

    Android使用Canvas繪制圓形進(jìn)度條效果

    這篇文章主要為大家詳細(xì)介紹了Android使用Canvas繪制圓形進(jìn)度條效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-10-10
  • Android OpenGL ES 實(shí)現(xiàn)抖音傳送帶特效(原理解析)

    Android OpenGL ES 實(shí)現(xiàn)抖音傳送帶特效(原理解析)

    這篇文章主要介紹了Android OpenGL ES 實(shí)現(xiàn)抖音傳送帶特效,抖音傳送帶特效推出已經(jīng)很長(zhǎng)一段時(shí)間了,前面也實(shí)現(xiàn)了下,最近把它整理出來(lái)了,如果你有仔細(xì)觀測(cè)傳送帶特效,就會(huì)發(fā)現(xiàn)它的實(shí)現(xiàn)原理其實(shí)很簡(jiǎn)單,需要的朋友可以參考下
    2022-07-07
  • Android實(shí)現(xiàn)相冊(cè)中圖片上傳或下載

    Android實(shí)現(xiàn)相冊(cè)中圖片上傳或下載

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)相冊(cè)中圖片上傳或下載,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-05-05
  • Android中FontMetrics的幾個(gè)屬性全面講解

    Android中FontMetrics的幾個(gè)屬性全面講解

    下面小編就為大家?guī)?lái)一篇Android中FontMetrics的幾個(gè)屬性全面講解。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2016-11-11
  • Android實(shí)現(xiàn)界面跳轉(zhuǎn)功能

    Android實(shí)現(xiàn)界面跳轉(zhuǎn)功能

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)界面跳轉(zhuǎn)功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-09-09
  • Android內(nèi)置SQLite的使用詳細(xì)介紹

    Android內(nèi)置SQLite的使用詳細(xì)介紹

    這篇文章主要介紹了Android內(nèi)置SQLite的使用詳細(xì)介紹,文章通過(guò)文章展開(kāi)詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下
    2022-09-09
  • Android UI控件之Gallery實(shí)現(xiàn)拖動(dòng)式圖片瀏覽效果

    Android UI控件之Gallery實(shí)現(xiàn)拖動(dòng)式圖片瀏覽效果

    這篇文章主要為大家詳細(xì)介紹了Android UI控件之Gallery實(shí)現(xiàn)拖動(dòng)式圖片瀏覽效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-12-12
  • Android仿微信界面的導(dǎo)航以及右上角菜單欄效果

    Android仿微信界面的導(dǎo)航以及右上角菜單欄效果

    這篇文章主要介紹了Android仿微信界面的導(dǎo)航以及右上角菜單欄效果,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,一起跟隨小編過(guò)來(lái)看看吧
    2018-05-05
  • Android動(dòng)態(tài)布局使用詳解

    Android動(dòng)態(tài)布局使用詳解

    這篇文章主要為大家詳細(xì)介紹了Android動(dòng)態(tài)布局的使用方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-07-07
  • Eclipse安裝ADT插件速度慢的解決方法

    Eclipse安裝ADT插件速度慢的解決方法

    這篇文章主要介紹了Eclipse安裝ADT插件速度慢的解決方法,涉及基于Apache的反向代理與hosts文件的設(shè)置方法,需要的朋友可以參考下
    2015-12-12

最新評(píng)論