Android學習第一課

來源:互聯網
上載者:User

標籤:android   style   blog   http   color   io   os   使用   java   

首先看一個android項目中各個包的作用

下面看幾個常用的控制項:

1、 TextView顯示文字框控制項

2、 EditText輸入文字框

TextView控制項常用屬性:

id----控制項的id

layout_width----控制項的寬度

layout_height----控制項的高度

text----常值內容

textSize----文字大小

textColor----文本顏色

background----控制項背景

EditText控制項常用屬性

id----控制項的id

layout_width----控制項的寬度

layout_height----控制項的高度

text----常值內容

textSize----文字大小

textColor----文本顏色

background----控制項背景

hint----輸入提示文本

inputType----輸入文本類型

 控制項寬度高度可以可選值為:

wrap_content:包裹實際常值內容,也就是字型有多寬控制項就多寬。

match_parent:當前控制項鋪滿父類容器—在2.3API之後添加的一個屬性值

fill_parent:當前控制項鋪滿父類容器---在2.3API之前的一個屬性值

 AutoCompleteTextView和MultiAutoCompleteTextView

AutoCompleteTextView動態匹配輸入的內容,如百度搜尋引擎,當輸入文本時可以根據內容顯示匹配的熱門資訊。

常用屬性,例如id、width、height等與其他控制項相同

專屬的屬性:

android:completionThreshold =“2”----設定輸入多少字元時自動匹配

MultiAutoCompleteTextView可支援多個值(在多次輸入情況下),分別用分隔字元分開,並且在每個值選中的時候再次輸入值時會自動去匹配,可用在發簡訊,發郵件時選擇連絡人這種類型中。

屬性與AutoCompleteTextView基本相同,在使用MultiAutoCompleteTextView時需要設定一個分隔字元,即以什麼符號分割多個輸入。可以使用setTokenzier()進行設定。

例如:

mxtx.setTokenizer(newMultiAutoCompleteTextView.CommaTokenizer());

在使用AutoCompleteTextView和MultiAutoCompleteTextView時需要對其綁定監聽器,具體步驟如下:

package com.example.test;import android.os.Bundle;import android.app.Activity;import android.widget.ArrayAdapter;import android.widget.AutoCompleteTextView;import android.widget.MultiAutoCompleteTextView;public class MainActivity extends Activity {private AutoCompleteTextView acTextView;private String[] res = {"beijing","beijing1","shan","shandong","shanxi","hebei","henan","hexi"};private MultiAutoCompleteTextView mxtx;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        /*         * 第一步:初始化控制項         * 第二步:需要一個適配器(適配文字框的輸入內容)         * 第三步:初始化資料來源(去匹配文字框輸入的內容)         * 第四步:將adapter與當前AutoCompleteTextView綁定         */        acTextView = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,        android.R.layout.simple_list_item_1, res);        acTextView.setAdapter(adapter);                mxtx = (MultiAutoCompleteTextView) findViewById(R.id.multiAutoCompleteTextView1);        mxtx.setAdapter(adapter);        //設定以逗號為分隔字元        mxtx.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());    }        }


 

Android學習第一課

聯繫我們

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