android學習筆記一

2021-08-31 05:02:55 字數 1901 閱讀 1012

1、設定textview值:

(1):textview tv1 = (textview)findviewbyid(r.id.tv1);

tv1.settext=("要設定的內容");

(2):在layout.xml布局頁面設定android:text="@string/tv1"

2、背景顏色:

(1)配置檔案改變android:background="@drawable/white"

(2)程式**改變

從資源檔案獲取背景顏色

resources resources = getbasecontext().getresources();

drawable drawable = resources.getdrawable(r.drawable.white);

//設定背景顏色

textview tv1 = (textview)findviewbyid(r.id.tv1);

tv1.setbackground(drawable);

//改變字型顏色

tv1.settextcolor(color.magenta);

3、螢幕物件:

displaymetrics dm = new displaymetrics();

getwindowmanager().getdefaultdisplay().getmetrics(dm);

dm.widthpixels獲取寬度

dm.heightpixels獲取高度

4、按鈕:

button btn1 = new button

//需要呼叫onclicklistener方法

btn1.setonclicklistener(new button.onclicklistener()

})5、兩個activity之間通訊

(1)需要使用intent

intent intent = new intent();

intent.setclass(class.this,other.class);

//呼叫

startactivity(intent);

class.this.finish();

(2)資料傳輸使用bundle,其類似與hashmap

bundle bundle = new bundle();

bundle.putdouble(key,value);

bundle.putstring(key,value);

//傳輸資料

intent.putextras(bundle);

(3)返回結果到前乙個activity

一、startactivityforresult(intent,0);

二、覆蓋onactivityresult方法

三、bundle bundle = data.getextras();

(4)必須在androidmanifest.xml新增新增的activity

6、android控制項

(1)textview頁面顯示標籤

(2)edittext編輯框

(3)button按鈕

(4)imagebutton按鈕

toast資訊提示小物件,會自動消失

toast.maketext(class.this,"text",long).show();

alertdialog dialog = new alertdialog.builder(this);

dialog.setmessage("text");

dialog.show();

(7)checkbox核取方塊

事件:ontouchlistener()

}(8)radiogroup單選框

事件:oncheckedchanglistener()

}

android學習筆記 一

xmlns android www.android 布局方式 android orientation vertival 空間布局方式是垂直往下布局 android layout width fill parent 把上層控制項填充滿 android layout height fill parent...

Android 學習筆記一

private string tag codeview codeview 為乙個標誌,一般為acvitity的名字 只要在想列印的地方寫上該 就可以列印相應的東西 log.v tag,string string為要列印的字串 包含語音包 import android.speech.tts.textt...

Android學習筆記《一》 簡介

1.什麼是android 維基百科 android 是一種以linux為基礎的開放原始碼作業系統,主要使用於便攜裝置。目前尚未有統一中文名稱,安卓 或 安致 是在中國大陸比較流行的稱呼。android作業系統最初由安迪 魯賓 andy rubin 創辦 5 最初主要支援手機。2005年由google...