




已閱讀5頁,還剩8頁未讀, 繼續(xù)免費閱讀
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
一、實驗名稱:實驗7 使用Intent和Android應(yīng)用資源二、實驗日期:2016-04-15三、實驗?zāi)康模?、掌握Intent的幾種常用的屬性。2、Android系統(tǒng)內(nèi)置Intent的使用。3、定義、使用Android應(yīng)用的資源。四、實驗用的儀器和材料:Windows+Eclipse+jdk+sdk+adt五、實驗的步驟和方法:實驗一: Intent的Action屬性的使用Main.xml Second.xml Week07_01Activity.javapackage com.week07.lab01;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;public class Week07_01Activity extends Activity /定義一個Action常量final static String JHY_ACTION = ent.action.JHY_ACTION; /定義一個Category常量final static String JHY_CATEGORY = ent.category.JHY_CATEGORY; public void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); setContentView(R.layout.main); Button bn = (Button) findViewById(R.id.bn); bn.setOnClickListener(new OnClickListener() public void onClick(View arg0) Intent intent = new Intent(); /設(shè)置Action屬性 intent.setAction(Week07_01Activity.JHY_ACTION); /添加Category屬性 intent.addCategory(Week07_01Activity.JHY_CATEGORY); startActivity(intent); ); SecondActivity.javapackage com.week07.lab01;import java.util.Set;import android.app.Activity;import android.os.Bundle;import android.widget.EditText;public class SecondActivity extends Activity public void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState);setContentView(R.layout.second);EditText show =(EditText) findViewById(R.id.show);/獲取該Activity對應(yīng)的Intent的Action屬性String action = getIntent().getAction();/顯示Action屬性show.setText(Action為:+action);EditText cate = (EditText) findViewById(R.id.cate);/ 獲取該Activity對應(yīng)的Intent的Category屬性Set cates = getIntent().getCategories();/ 顯示Action屬性cate.setText(Category屬性為: + cates); AndroidManifest.xml 實驗二: Android系統(tǒng)內(nèi)置Intent使用,自己編寫布局文件main.xml代碼Main.xml Week07_02Activity.javapackage com.week07.lab02;import android.app.Activity;import android.content.Intent;import .Uri;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;public class Week07_02Activity extends Activity /* Called when the activity is first created. */ Override public void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); setContentView(R.layout.main); Button bn = (Button)findViewById(R.id.bn); /為bn按鈕添加一個監(jiān)聽器 bn.setOnClickListener(new OnClickListener()public void onClick(View v) /創(chuàng)建IntentIntent intent = new Intent();String data = ;/根據(jù)指定字符串解析出Uri對象Uri uri =Uri.parse(data);/ 為Intent設(shè)置Action屬性intent.setAction(Intent.ACTION_VIEW);/設(shè)置Data屬性intent.setData(uri);startActivity(intent); ); Button edit = (Button) findViewById(R.id.edit);/ 為edit按鈕添加一個監(jiān)聽器edit.setOnClickListener(new OnClickListener() public void onClick(View v) / 創(chuàng)建IntentIntent intent = new Intent();/ 為Intent設(shè)置Action屬性intent.setAction(Intent.ACTION_EDIT);String data = content:/com.android.contacts/contacts/1;/根據(jù)指定字符串解析出Uri對象Uri uri =Uri.parse(data);/設(shè)置Data屬性intent.setData(uri);startActivity(intent););Button call = (Button) findViewById(R.id.call);/ 為edit按鈕添加一個監(jiān)聽器call.setOnClickListener(new OnClickListener() public void onClick(View v) / 創(chuàng)建IntentIntent intent = new Intent();/ 為Intent設(shè)置Action屬性(動作為:撥號)intent.setAction(Intent.ACTION_DIAL); String data = tel/ 根據(jù)指定字符串解析出Uri對象Uri uri =Uri.parse(data); / 設(shè)置Data屬性intent.setData(uri); startActivity(intent);); 實驗三:Android字符串資源,顏色資源,數(shù)組資源等的使用程序,補(bǔ)充代碼Main.xml Colors.xml #F00 #0F0 #00F #0FF #F0F #FF0 #07F #70F #F70 Dimens.xml 8dp 60dp 66dp 18dpArrays.xml color/c1 color/c2 color/c3 color/c4 color/c5 color/c6 color/c7 color/c8 color/c9 string/c1 string/c2 string/c3 string/c4 string/c5 string/c6 string/c7 string/c8 string/c9 瘋狂Java講義 瘋狂Ajax講義 瘋狂Android講義 Strings.xml week07-03 Android應(yīng)用資源的使用 F00 0F0 00F 0FF F0F FF0 07F 70F F70Week07_03Activity.javapackage com.week07.lab03;import android.app.Activity;import android.content.res.Resources;import android.content.res.TypedArray;import android.os.Bundle;import android.view.View;import android.view.ViewGroup;import android.widget.BaseAdapter;import android.widget.GridView;import android.widget.TextView;public class Week07_03Activity extends Activity / 獲取系統(tǒng)定義的數(shù)組資源String texts; public void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); setContentView(R.layout.main); texts = getResources().getStringArray(R.array.string_arr);/ 創(chuàng)建一個BaseAdapter對象BaseAdapter ba = new BaseAdapter() public int getCount() / 指定一共包含9個選項return texts.length;public Object getItem(int position) / 返回指定位置的文本return textsposition;public long getItemId(int position) return position;/ 重寫該方法,該方法返回的View將作為的GridView的每個格子public View getView(int position, View convertView, ViewGroup parent) TextView text = new TextView(Week07_03Activity.this);Resources res = Week07_03Activity.this.getResources();/ 使用尺度資源來設(shè)置文本框的高度、寬度text.setWidth(int) res.getDimension( R.dimen.cell_width);text.setHeight(int) res.getDimension( R.dimen.cell_height);/ 使用字符串資源設(shè)置文本框的內(nèi)容text.setText(textsposition);TypedArray icons = res.obtainTypedArray( R.array.plain_arr);/ 使用顏色資源來設(shè)置文本框的 背景色 text.setBackgroundDrawable(icons.getDrawable(position);text.setT
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 測繪資質(zhì)認(rèn)證管理辦法
- 景德鎮(zhèn)陶瓷大學(xué)《信息圖形設(shè)計》2023-2024學(xué)年第一學(xué)期期末試卷
- 海信集團(tuán)預(yù)算管理辦法
- 海南大學(xué)食堂管理辦法
- 海南滯留人員管理辦法
- 海原電纜保護(hù)管理辦法
- ??诎紫伔乐喂芾磙k法
- 海洋監(jiān)察制服管理辦法
- 消毒用品注冊管理辦法
- 消防產(chǎn)品監(jiān)督管理辦法
- 江蘇省2025年中職職教高考文化統(tǒng)考數(shù)學(xué)試題答案
- GB/Z 27021.13-2025合格評定管理體系審核認(rèn)證機(jī)構(gòu)要求第13部分:合規(guī)管理體系審核與認(rèn)證能力要求
- 金氏五行升降中醫(yī)方集
- 前列腺癌根治術(shù)護(hù)理查房課件
- (完整版)UPS技術(shù)培訓(xùn)教材PPT(共-54張)課件
- 全國醫(yī)療服務(wù)價格項目規(guī)范(試行)
- 第三章_同步發(fā)電機(jī)勵磁自動調(diào)節(jié)
- 食品用塑料包裝容器工具等制品生產(chǎn)許可審查細(xì)則
- 財政部金融企業(yè)不良資產(chǎn)批量轉(zhuǎn)讓管理辦法(財金[2012]6號)
- 格賓擋墻結(jié)構(gòu)設(shè)計計算書
- 八年級上冊物理教案全冊
評論
0/150
提交評論