首頁 收藏 QQ群
 網(wǎng)站導(dǎo)航

ZNDS智能電視網(wǎng) 推薦當(dāng)貝市場

TV應(yīng)用下載 / 資源分享區(qū)

軟件下載 | 游戲 | 討論 | 電視計(jì)算器

綜合交流 / 評測 / 活動區(qū)

交流區(qū) | 測硬件 | 網(wǎng)站活動 | Z幣中心

新手入門 / 進(jìn)階 / 社區(qū)互助

新手 | 你問我答 | 免費(fèi)刷機(jī)救磚 | ROM固件

查看: 13492|回復(fù): 0
上一主題 下一主題
[教程]

Android 基本界面-文本編輯控件

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
發(fā)表于 2013-8-28 16:30 | 只看該作者 回帖獎勵 |倒序?yàn)g覽 |閱讀模式
7 1 TextView   
     
一般用來文本展示,繼承自,在包中。   
   
       他的常用子類有。   
   
       常用屬性設(shè)置:   
       android:text=“”         文字顯示   
       android:autoLink=””  鏈接類型。Web網(wǎng)址,email郵件,phone電話,map地圖。Linkify。   
     
       鏈接狀態(tài)時(shí),Web情況可直接調(diào)用瀏覽器進(jìn)行瀏覽。Email直接調(diào)用手機(jī)的Email軟件,phone轉(zhuǎn)到撥打電話頁面。   
   
        2   
     
上面的圖為AutoCompleteTextView和MultiAutoCompleteTextView   
   
        帶提示的輸入框,繼承自,在包中。   
        和都是自動提示,一個(gè)是單選,一個(gè)多選。   
常用屬性設(shè)置:   
        輸入幾個(gè)字符時(shí)提示   
   
        就是一個(gè)帶自動提示的,當(dāng)輸入字符時(shí),會出現(xiàn)提示窗口,點(diǎn)擊選擇即可。首先在中定義一個(gè),然后需要在設(shè)置數(shù)據(jù)源就可以了。的構(gòu)造方法三個(gè)參數(shù)為:上下文的,每行的布局,數(shù)據(jù)源。   
   
   
  1. this.autoCompleteTextView = (AutoCompleteTextView) super.findViewById(R.id.autoCompleteTextView);   
    ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, R.layout.arrayadapte_textview, CITY_NAMES);   
    this.autoCompleteTextView.setAdapter(arrayAdapter);
復(fù)制代碼
和的類似,也是帶有提示的輸入框。區(qū)別在于可以連續(xù)提示,選擇一個(gè)提示項(xiàng)后會自動添加一個(gè)分隔符,在輸入時(shí)繼續(xù)提示。則屬于單選模式的。   
   
        使用時(shí)需要設(shè)置分隔符類其他與一樣。   
   
   
  1. this.multiAutoCompleteTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
復(fù)制代碼
3 TextSwitcher   
   
        文字切換。繼承自在包中。   
        使用方法設(shè)置動畫。   
        例子,設(shè)置的動畫,并使用數(shù)字時(shí)鐘更改的字符串   
   
   
  1. public class SwitcherActivity extends Activity implements ViewSwitcher.ViewFactory, View.OnClickListener {   
       
       
    private Button buttonChangeText;   
       
    private TextSwitcher myTextSwitcher;   
       
    private DigitalClock myDigitalClock;   
       
       
    @Override   
       
    protected void onCreate(Bundle savedInstanceState) {   
       
    super.onCreate(savedInstanceState);   
       
    super.setContentView(R.layout.switcher);   
       
       
    this.buttonChangeText = (Button) super.findViewById(R.id.buttonChangeText);   
       
    this.myTextSwitcher = (TextSwitcher) super.findViewById(R.id.myTextSwitcher);   
       
    this.myDigitalClock = (DigitalClock) super.findViewById(R.id.myDigitalClock);   
       
    this.buttonChangeText.setOnClickListener(this);   
       
    this.myTextSwitcher.setFactory(this);   
       
       
    this.myTextSwitcher.setInAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_in));   
       
    this.myTextSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_out));   
       
       
    }   
       
       
    @Override   
       
    public View makeView() {   
       
    TextView textView = new TextView(this);   
       
    textView.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL);   
       
    textView.setTextSize(36);   
       
    return textView;   
       
    }   
       
       
    @Override   
       
    public void onClick(View v) {   
       
    this.myDigitalClock.addTextChangedListener(textWatcher);   
       
    }   
       
       
    private android.text.TextWatcher textWatcher = new android.text.TextWatcher() {   
       
       
    @Override   
       
    public void onTextChanged(CharSequence s, int start, int before, int count) {   
       
    SwitcherActivity.this.myTextSwitcher.setText(SwitcherActivity.this.myDigitalClock.getText());   
       
    }   
       
       
    @Override   
       
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {   
       
    }   
       
       
    @Override   
       
    public void afterTextChanged(Editable s) {   
       
    }   
       
    };   
       
    }
復(fù)制代碼
我們在來看看xml里的代碼吧   
   
   
  1. <?xml version="1.0" encoding="utf-8"?>   
       
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"   
       
    android:layout_width="fill_parent"   
       
    android:layout_height="fill_parent"   
       
    android:orientation="vertical"   
       
    android:gravity="center_horizontal">   
       
       
    <Button android:id="@+id/buttonChangeText"   
       
    android:layout_width="wrap_content"   
       
    android:layout_height="wrap_content"   
    android:text="開始" />   
       
       
    <DigitalClock android:id="@+id/myDigitalClock"   
       
    android:layout_width="fill_parent"   
       
    android:layout_height="wrap_content"   
       
    android:textSize="36dip"/>   
       
       
    <TextSwitcher android:id="@+id/myTextSwitcher"   
       
    android:layout_width="fill_parent"   
       
    android:layout_height="wrap_content" />   
       
       
    </LinearLayout>
復(fù)制代碼
這個(gè)就是我們常說的android控件,新手們要好好的看哦,每一個(gè)成功的實(shí)例都是我們一點(diǎn)一點(diǎn)積累起來的。大家要是對這篇文章有什么問題,我們可以回帖交流。希望高手帶帶我,少讓我走的彎路

上一篇:Android中EditText - 可編輯文本控件
下一篇:Android 如何使用Alarm

相關(guān)帖子

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

Archiver|新帖|標(biāo)簽|軟件|Sitemap|ZNDS智能電視網(wǎng) ( 蘇ICP備2023012627號 )

網(wǎng)絡(luò)信息服務(wù)信用承諾書 | 增值電信業(yè)務(wù)經(jīng)營許可證:蘇B2-20221768 丨 蘇公網(wǎng)安備 32011402011373號

GMT+8, 2024-10-19 14:38 , Processed in 0.061901 second(s), 15 queries , Redis On.

Powered by Discuz!

監(jiān)督舉報(bào):report#znds.com (請將#替換為@)

© 2007-2024 ZNDS.Com

快速回復(fù) 返回頂部 返回列表