欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

Android顏色配置器配置方法

一、Android Color設(shè)置

創(chuàng)新互聯(lián)建站于2013年成立,先為臨川等服務(wù)建站,臨川等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為臨川企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。

1、在xml文件中

想設(shè)置顏色直接設(shè)置background的屬性或者其他的color屬性。隨便設(shè)置一個(gè)顏色如#000,再點(diǎn)擊左邊的顏色方塊,彈出顏色選擇器選擇顏色

Android顏色配置器配置方法

2、在java代碼中

①Color.parseColor("#000");

tvShow.setBackgroundColor(Color.parseColor("#000"));

【提示】可以在布局文件中配置好顏色值,然后把用“#”表示的顏色帶到j(luò)ava代碼中用

②Color.BLACK 使用Color類自帶的顏色,不過都是一些基本色

tvShow.setBackgroundColor(Color.BLACK);

③定義Color資源文件,通過R.color.myColor引用

int color = R.color.myColor;
tvShow.setBackgroundResource(R.color.myColor);

Android顏色配置器配置方法

④Color.argb(a,r,g,b)方法:

tvShow.setBackgroundColor(Color.argb(255, 255, 0, 0));

分別是alpha、紅(red)、綠(green)、藍(lán)(blue)四個(gè)顏色值(ARGB)。每個(gè)數(shù)字取值0-255,因此一個(gè)顏色可以用一個(gè)整數(shù)來表示。為了運(yùn)行效率,Android編碼時(shí)用整數(shù)Color類實(shí)例來表示顏色。

【提示】通過此方法傳入對(duì)應(yīng)的透明度值,紅色值,綠色值,藍(lán)色值進(jìn)行顏色配置。因此我們可以通過此方法做一個(gè)簡(jiǎn)單的顏色配置器。

二、顏色配置器案例

Android顏色配置器配置方法

1、【效果】

界面設(shè)計(jì)的比較粗糙,希望大家能學(xué)到實(shí)現(xiàn)效果,優(yōu)化界面。

2、【項(xiàng)目結(jié)構(gòu)】

Android顏色配置器配置方法

3、【代碼】

 ①activity_main.xml布局文件

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 tools:context=".MainActivity"
 android:orientation="vertical">
 <TextView
  android:text="請(qǐng)輸入argb值:"
  android:textSize="20sp"
  android:textColor="#000"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:layout_margin="10dp"/>
 <LinearLayout
  android:layout_width="match_parent"
  android:layout_height="50dp"
  android:orientation="horizontal">
  <EditText
   android:id="@+id/etA"
   android:layout_width="0dp"
   android:layout_weight="1"
   android:layout_height="match_parent"
   android:layout_margin="1dp"
   android:hint="透明度(0-255)"
   android:inputType="number"/>
  <EditText
   android:id="@+id/etR"
   android:hint="紅(0-255)"
   android:layout_width="0dp"
   android:layout_weight="1"
   android:layout_height="match_parent"
   android:background="#f00"
   android:layout_margin="1dp"
   android:gravity="center"
   android:inputType="number"/>
 </LinearLayout>
 <LinearLayout
  android:layout_width="match_parent"
  android:layout_height="50dp"
  android:orientation="horizontal">
  <EditText
   android:id="@+id/etG"
   android:hint="綠(0-255)"
   android:layout_width="0dp"
   android:layout_weight="1"
   android:layout_height="match_parent"
   android:background="#0f0"
   android:layout_margin="1dp"
   android:gravity="center"
   android:inputType="number"/>
  <EditText
   android:id="@+id/etB"
   android:hint="藍(lán)(0-255)"
   android:layout_width="0dp"
   android:layout_weight="1"
   android:layout_height="match_parent"
   android:background="#00f"
   android:layout_margin="1dp"
   android:gravity="center"
   android:inputType="number"/>
 </LinearLayout>
 <TextView
  android:id="@+id/tv_show"
  android:text="TextView"
  android:layout_width="200dp"
  android:layout_height="200dp"
  android:background="#000"
  android:layout_gravity="center"
  android:layout_marginTop="20dp"
  />
 <Button
  android:id="@+id/btn"
  android:text="確定配置"
  android:layout_margin="20dp"
  android:layout_width="match_parent"
  android:layout_height="wrap_content" />
</LinearLayout>

【提示】EditText 中hint屬性:這是設(shè)置輸入框內(nèi)的提示文字。 inputType屬性:設(shè)置輸入框輸入的文本類型,此處設(shè)置為整數(shù)型

②MainActivity.java文件

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
 private EditText etA;
 private EditText etR;
 private EditText etG;
 private EditText etB;
 private TextView tvShow;
 private Button btn;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  initView();
 }
 private void initView() {
  etA = (EditText) findViewById(R.id.etA);
  etR = (EditText) findViewById(R.id.etR);
  etG = (EditText) findViewById(R.id.etG);
  etB = (EditText) findViewById(R.id.etB);
  tvShow = (TextView) findViewById(R.id.tv_show);
  btn = (Button) findViewById(R.id.btn);
  btn.setOnClickListener(this);
 }
 @Override
 public void onClick(View v) {
  switch (v.getId()) {
   case R.id.btn:
    submit();
    break;
  }
 }
 private void submit() {
  // validate
  if (!etA.getText().equals("")&&!etB.getText().equals("")
    &&!etR.getText().equals("")&&!etG.getText().equals("")) {
   //對(duì)用戶輸入的數(shù)值進(jìn)行判斷是否為空。避免空字符無法轉(zhuǎn)換為int異常
   int et_a = Integer.parseInt(etA.getText().toString());
   int et_r = Integer.parseInt(etR.getText().toString());
   int et_g = Integer.parseInt(etG.getText().toString());
   int et_b = Integer.parseInt(etB.getText().toString());
   tvShow.setBackgroundColor(Color.argb(et_a, et_r, et_g, et_b));
  }else {
   Toast.makeText(this, "輸入的值不能為空", Toast.LENGTH_SHORT).show();
  }
 }
}

總結(jié)

以上所述是小編給大家介紹的Android顏色配置器配置方法,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)創(chuàng)新互聯(lián)網(wǎng)站的支持!

標(biāo)題名稱:Android顏色配置器配置方法
文章鏈接:http://www.chinadenli.net/article36/ishesg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站設(shè)計(jì)網(wǎng)站改版域名注冊(cè)網(wǎng)站策劃網(wǎng)站內(nèi)鏈

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作