黑馬程序員的視頻: 只要精通一門技能就能防身,切不可范范而學(xué)不可只懂皮毛。
Log.v() 最低級,打印意義最小的日志信息
Log.d() 打印出調(diào)試信息,調(diào)試信息和分析問題
Log.i() 打印出重要的數(shù)據(jù),用戶的行為
Log.w() 打印出一些警告
Log.e() 打印出錯誤信息,如果程序進(jìn)入catch語句,有重大錯誤必須盡快修復(fù)
DE729F04BB819
adb not responding 進(jìn)入cmd 輸入netstat -aon |findstr "5037"
殺死127.0.0.0的進(jìn)程 一般是360等助手
alt+enter快速導(dǎo)入包
D:ANDSDK/tools/draw9patch
繪畫9圖
導(dǎo)入其他人包時
修改 build.gradle中的 BuildToolsVersion:"23.0.1"
hardwear.camera2
優(yōu)化布局層次:
include merge ViewStub
光標(biāo)變粗 fn+delete
Fragment: 好處在于 內(nèi)部的控件和事件由自己管理
10.ViewPager: 寫在mainactivity中
如果有l(wèi)istview 在tab01上 還是寫在mainactivity中
LocationClient
BDLocationListener 耗時的操作
如果runapp出現(xiàn)
Error type 3
Error: Activity class {com.example.lw.nine_patch/com.example.lw.nine_patch.MainActivity} does not exist.
拔掉數(shù)據(jù)線 重新連接在重新啟動
多用stackoverflow 提高自己英語水平
Layout-sw600dp文件夾和layout文件夾進(jìn)是一個級別
隱藏消息框時 提示必須放在content之前
應(yīng)該把extends appCompatactivity 改成 activity
或者直接 在activity manifest中聲明 theme noactionbar
Android依賴外部文件庫
1.file->new->import moudle->lib zxing
2.procject stucture->moudle->+ 選擇libzxing
SharedPreference 兩個參數(shù)
第一個參數(shù)指 SharePreferenced文件名稱 第二個設(shè)定模式
getString(key,value)
新建class 里面有enum和interface
所以萬事不要放棄,請堅持,請美麗的活著
19.Fiddler使用
Fiddler是最好的WEB調(diào)試工具之一,是一款非常流行并且實(shí)用的http抓包工具,它的原理是在本機(jī)開啟了一個http的代理服務(wù)器,然后它會轉(zhuǎn)發(fā)所有的http請求和響應(yīng),它記錄所有的客戶端和服務(wù)器的http、https請求。
允許監(jiān)視、設(shè)置斷點(diǎn)、修改輸入輸出數(shù)據(jù),F(xiàn)iddler對開發(fā)和測試來說都有很多幫助。
1.啟動Fiddler,打開菜單欄中的 Tools > Fiddler Options,打開“Fiddler Options”對話框。
2.在Fiddler Options”對話框切換到“Connections”選項(xiàng)卡,然后勾選“Allow romote computers to connect”后面的復(fù)選框,然后點(diǎn)擊“OK”按鈕。
3.在本機(jī)命令行輸入:ipconfig,找到本機(jī)的ip地址
4.打開android設(shè)備的“設(shè)置”->“WLAN”,找到你要連接的網(wǎng)絡(luò),在上面長按,然后選擇“修改網(wǎng)絡(luò)”,彈出網(wǎng)絡(luò)設(shè)置對話框,然后勾選“顯示高級選項(xiàng)”。
5.在“代理”后面的輸入框選擇“手動”,在“代理服務(wù)器主機(jī)名”后面的輸入框輸入電腦的ip地址,在“代理服務(wù)器端口”后面的輸入框輸入8888,然后點(diǎn)擊“保存”按鈕。
6.然后啟動android設(shè)備中的瀏覽器,訪問百度的首頁,在fiddler中可以看到完成的請求和響應(yīng)數(shù)據(jù)。
Chrome插件:
1.JSONView 對接api接口時,一般都是默認(rèn)返回json格式,自動排列Json數(shù)據(jù)
下載東西不要死板 把地址放到迅雷里面下載(電腦分屏的原理)
1、Studio中有Project和Module的概念,前面說到Studio中一個窗口只能有一個項(xiàng)目,
即Project,代表一個workspace,但是一個Project可以包含多個Module,比如你項(xiàng)目引用的Android Library, Java Library等,這些都可以看做是一個Module;
2、上述目錄中將java代碼和資源文件(圖片、布局文件等)全部歸結(jié)為src,
在src目錄下有一個main的分組,同時劃分出java和res兩個文件夾,java文件夾則相當(dāng)于Eclipse下的src文件夾,res目錄結(jié)構(gòu)則一樣.
23.++i和i++的區(qū)別
如果有表達(dá)式 a = i++ 它等價于 a = i ; i = i + 1;
如果有表達(dá)式 a = ++i 它等價于 i = i + 1; a = i;
int i=0;
while( i++ < 5 ) //先用i的原值與5比較,比較完成后,無論結(jié)果是真還是假,都要再進(jìn)行i=i+1運(yùn)算
{
System.out.print( i+ " ");
}
這個循環(huán)運(yùn)行5次,輸出 1 2 3 4 5,最后的i值是6
int i=0;
while( ++i < 5 ) //先進(jìn)行i=i+1運(yùn)算,然后用i的新值與5比較,判斷結(jié)果是真還是假
{
System.out.print( i+ " ");
}
遇到重復(fù)定義 多使用數(shù)組
private int index;
private int images[]={R.drawable.image1,R.drawable.image2,R.darwable.image3}
public void run(){
index++;
index=index%3;//取余數(shù)
imageView.setImageResource(images[index]);
}
25.gravity和layout_gravity
android:gravity:是對view控件本身來說的,是用來設(shè)置view本身的內(nèi)容應(yīng)該顯示在view的什么位置,默認(rèn)值是左側(cè)。
android:layout_gravity:是相對于包含改元素的父元素來說的,設(shè)置該元素在父元素的什么位置
http://ww1.sinaimg.cn/mw690/85d82f62jw1f3ibad8of3j20qo0qoju6.jpg
JsonObjectRequest jsonObjectRequest=new JsonObjectRequest(Request.Method.GET, JSONDateUrl, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d("error","對不起,有問題");
}
} ,new Response.ErrorListener(){
@Override
public void onErrorResponse(VolleyError volleyError) {
Log.d("error","對不起,有問題");
}
});
右下角沒有聲音小圖標(biāo) 任務(wù)管理器 結(jié)束explorer.exe 然后文件新建 在輸入explorer
28.Fragment和Actity通信
Fragment 與 Activity 可能還需要相互傳遞數(shù)據(jù)的方式:
- Activity 向 Fragment 傳遞數(shù)據(jù) : 在 Activity 中創(chuàng)建 Bundle 數(shù)據(jù)包 , 并調(diào)用 Fragment 的 setArguments(Bundle bundle) 方法即可將 Bundle 數(shù)據(jù)包傳給 Fragment 。
- Fragment 向 Activity 傳遞數(shù)據(jù)或 Activity 需要在 Fragment 運(yùn)行中進(jìn)行實(shí)時通信: 在 Fragment 中定義一個 內(nèi)部回調(diào)接口 ,再讓包含該 Fragment 的 Activity 實(shí)現(xiàn)該回調(diào)接口,這樣 Fragment 即可調(diào)用該回調(diào)方法將數(shù)據(jù)傳給 Activity 。
獲取傳來的值:
String str = (String)getArguments().get(“str”);
29.View
View 是最基本的UI組件,繪制矩形區(qū)域
View view=inflater.inflate(R.layout.fragment_list_refresh,container,false);
Android2.2中match_parent和fill_parent是一個意思 .兩個參數(shù)意思一樣,match_parent更貼切,于是從2.2開始兩個詞都可以用。那么如果考慮低版本的使用情況你就需要用fill_parent了
30.Listview adapter三個參數(shù)
lv=(ListView)view.findViewById(R.id.listview);
//通過泛型來指定需要適配的數(shù)據(jù)類型,再通過構(gòu)造函數(shù)將適配的數(shù)據(jù)傳入
//adapter三個參數(shù) 當(dāng)前上下文getActivity() listview子項(xiàng)布局Id(這是系統(tǒng)自帶簡單text),需要適配的數(shù)據(jù)
lv.setAdapter(new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1,getData()));
return view;
31.LayoutInflater對象 調(diào)用inflater.inflate() 動態(tài)加載布局
兩個參數(shù)或者三個參數(shù)
inflate(resource,null)=inflate(reource,root,false)
inflate(resource,root)=inflate(reource,root,true)
參數(shù)1 布局Id 參數(shù)二root作用 false使得layout_height和layout_width生效 ture加載父布局
1.在類似 adapter 的 getView 和 fragment 的 onCreateView 等方法中,應(yīng)該使用 inflate(resource, root, false) 而不是 inflate(resource, null)。后者會使得布局最外層的 layout_width, layout_height 等屬性失效。
2.自定義 view 的構(gòu)造方法中(特指參考文中的組合控件),我們應(yīng)該使用 inflate(resource, root) 或 infalte(resource, root, true
新版v4有這個類 ActivityOptionsCompat 我們通過這個類添加動畫和啟動Activity
關(guān)注Material Design設(shè)計
R文件找不到
Android Studio 提示Cannot resolve symbol 'R'
1.Just clean your project and Sync Project with Gradle File.
2.檢查xml文件 clean工程
在github上找demo 看源碼
Android widget指應(yīng)用程序嵌入在主屏幕的小部件 小插件
37.item selector
Android Selector主要是用來改變listview和button控件的默認(rèn)背景
1)drawable目錄下放置ic_clear.xml 添加selector
2)
<item android:drawable="@drawable/pic1" />
<item
android:state_focused="false"
android:drawable="@drawable/no_image"/>
<item android:state_focused="true"
android:drawable="@drawable/textfield_search_selected"/>
< !--選中時的圖片背景-->
<item android:state_selected="true" android:drawable="@drawable/pic4" />
<item android:state_focused="true" android:drawable="@drawable/pic5" />
3)引用:
listView中:(1)android:listselector="@drawable/ic_clear"
(2)android:background="@drawable/ic_clear"
(3)Drawable drawable=getResource.getDrawable(R.drawable.ic_clear)
listview.setSelector(drawable)
38.menu使用
android:showAsAction="never" 表示隱藏 在點(diǎn)擊.擴(kuò)展時會顯示
android:showAsAction="always" 一直在標(biāo)題欄顯示
android:orderInCategory="3" 重要性 顯示在第幾個
item表示子項(xiàng)
group表示具有相同屬性的一系列item組成
group屬性:顯示示或隱藏所有的菜單項(xiàng) ,使用方法 setGroupVisible()
Enable 或 disable 所有的菜單項(xiàng),使用方法 setGroupEnabled()
指定所有的菜單項(xiàng)是否是 checkable ,使用方法 setGroupCheckable()
android:checkableBehavior:single(只有一個菜單項(xiàng)能被選中) all none
在mainActivity中調(diào)用
public boolean onCreateOptionsMenu(){
getMenuInflater().inflate(R.menu.menu1, menu);
return true;
}
public boolean onOptionsItemSelected(menuItem item){
switch(itme.getId()){
case:
break;
case:
break;
}
return super.onOptionsItemSelected(item);
}
39.ToolBar menu和ActionBar的區(qū)別
ActionBar代替了頂部的標(biāo)題欄,可以顯示導(dǎo)航欄和標(biāo)題功能,可以顯示關(guān)鍵的Action,
Action在程序運(yùn)行過程中始終保持可見狀態(tài) sdk21被棄用 推薦ToolBar
menu menu也可以執(zhí)行程序的各種功能,但需要點(diǎn)擊menu鍵才會顯示,而且很多anroid設(shè)備不再有
menu鍵 menu也被拋棄
ToolBar 不是Android Design Support Library的一部分而是在這個庫中需要與其他組件一起使用,隱藏 Action Bar 并且切換到 Toolbar,因?yàn)檫@些有奇妙功能的新庫,包括 Design Support Library 的組件中,都被設(shè)計為和 Toolbar 協(xié)同工作
1.<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
2.放在 CoordinatorLayout 的東西必須被設(shè)計和實(shí)現(xiàn)成與它一起合作的,否則將不與任何其他兄弟 views(sibling views) 協(xié)作,提供一個組件讓CoordinatorLayout與toolbar一起工作
只是簡單的用AppBarLayout包裹 Toolbar
40.DrawerLayout側(cè)滑學(xué)習(xí) NavigationView
41.JAVA8的新特性
Android開發(fā)中,強(qiáng)烈推薦使用retrolambda這個gradle插件,這樣你就可以在你的代碼中使用lambda了。
42.Style定義和使用(zhihu那個demo布局)
在style.xml中定義style,可以減少重復(fù)布局
1)使用Android本身屬性,例如
<style name="cardQusetionTextStyle" parent="BaseCardTextStyle">
<item name="android:textsize">17sp</item>
<item name="android:textStyle">bold</item>
</style>
<style name="cardOverflowIconStyle">
<item name="android:contentDescription">@string/share_this_news</item>
<item name="android:layout_width">24dp</item>
<item name="android:layout_height">24dp</item>
<item name="android:src">@drawable/ic_card_overflow</item>
<item name="android:layout_alignParentRight">true</item>
</style>
2)自定義style item 需要在style中使用命名控件的地方換成自定義控件的包名即可(注意:是包名,不帶自定義控件的名字)
<resources xmlns:android="http://schemas.android.com/apk/res/android" >
<style name="test" >
<item name="com.zhufuing:name_text">hello,world!</item>
</style>
</resources> com.zhufuing是需要使用style的那個包名
43.Material Design 中ToolBar
app:popupTheme,這個屬性就是用來自定義我們彈出的菜單的樣式,
app:popupTheme="ThemeOverlay.AppCompat.Light",那么這個Overflow彈出的是白底黑字
app:popupTheme="@style/AppTheme.PopupOverlay" 黑底白字
app:layout_scrollFlags=”scroll|enterAlways” 一旦向上滾動toolbar就可見
Scroll 表示向下滾動時,這個View會被滾出屏幕范圍直到隱藏.
,enterAlwaysCollapsed 再定義android:minHeight="100dp" 最小高度何時進(jìn)入
exitUntilCollapsed 再定義android:minHeight="100dp" 最小高度titleview何時進(jìn)入
實(shí)現(xiàn)視差效果,在用戶滾動的時候title的高度也會隨著改變。
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"></android.support.v7.widget.Toolbar>
<ImageView
android:src="@drawable/cheese_1"
app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax" 我們添加一個定義了app:layout_collapseMode="parallax" 屬性的ImageView。
android:minHeight="100dp"/>
</android.support.design.widget.CollapsingToolbarLayout>
在可以滾動的View上設(shè)置屬性 app:layout_behavior.
44.tools屬性
Layout tools:生成只在Android Studio IDE才能預(yù)覽的效果
例如tools:text="test title"
tools:ignore="ContentDescription, RtlHardcoded" 將XML Editor 小黃點(diǎn)取消
45.ReclyclerView
Android:drawSelectorOnTop="true" 點(diǎn)擊某一條記錄,顏色會顯示在最上面,記錄上的文字被遮住,所以點(diǎn)擊文字不放,文字就看不到
46.為什么使用Content Provider
Content Provider用于在不同應(yīng)用程序之間共享數(shù)據(jù)
與SharedPreferences不同(全局可讀寫操作模式 不管是private multiprocess),
content provider可以選擇對那一部分?jǐn)?shù)據(jù)共享 可以保證隱私數(shù)據(jù)
兩種用法 使用現(xiàn)有的內(nèi)容提供器訪問和操作數(shù)據(jù) 自己創(chuàng)建內(nèi)容提供器并未數(shù)據(jù)提供外部訪問接口
例如電話簿 短信 媒體庫都提供了數(shù)據(jù)的外部訪問接口
1.getContentResolver (ContentResolver類提供了真刪改查的功能)
2.getContentResolver.query(Uri參數(shù))
內(nèi)容URI 權(quán)限+路徑(包名+文件名)
content://com.example.app.provider/table1
內(nèi)容URI裝換成Uri對象
Uri uri=Uri.parse("content://com.example.app.provider/table1")
Cursor cursor=getContentResolver().query(uri,projection,selection,selectionArgs,sortOrder);
1.某個應(yīng)用程序下的表2.查詢的列名3.where約束條件4.為where占位符提供具體的值5.查詢結(jié)果的排序方式
查詢返回的cursor對象
if(cursor!=null){
while(cursor.moveToNext()){
String cloumn=cursor.getString(cursor.getColumnIndex("column1"));
Int column2=cursor.getInt(cursor.getCollumnIndex("column2"));
}
cursor.close();
}
插入更新(數(shù)據(jù)放到contentValues中)
ContentValues values=new ContentValues();
values.put("name","walsky");
values.put("pages",55);
getContentResolver().insert(uri,values);
values.put("name","wal");
values.put("pages",46);
getContentResolver().update(uri,values,"name = ? and pages = ?",new String[] {"text","1"})
刪除
getContentResolver().delete(uri,"colum2=?",new String[] {"1"});
自己的內(nèi)容提供器(extends ContentProvider,再重寫6個方法)
onCreate() query() insert() delete() update() getType() (根據(jù)Uri返回MIME類型)
自己創(chuàng)建的privider 要注冊
<provider
name
authority
exported="true" 表明是否能被訪問
tools可以覆蓋android的所有標(biāo)準(zhǔn)屬性,將android:換成tools:即可。同時在運(yùn)行的時候就連tools:本身都是被忽略的,不會被帶進(jìn)apk中。
AS alter+enter是查看錯誤的內(nèi)容
48.Android
項(xiàng)目地址:https://android.googlesource.com/或https://github.com/android
以上兩個項(xiàng)目,不解釋
49.SQLite數(shù)據(jù)庫
public class CoolweatherOpenHelper extends SQLiteOpenHelper{
public static final String Crete_Provice="Create table Province ("+
"id integer pirmary key autoincrement"
+"province_name text "+"province_code text )"
public static final String Create_City="Create table Ctiy ("+
"id integer primary key autoincrement "
+"city_name text "+"city_code text"
+"province_id integer )"
public static final String Create_Country="Create table country ("
+"id integer primary key autoincrement"+
" counter_name text"+"counter_code"+
"city_id integer ) "
public CoolweatherOpenHelper(Context context,String name,CursorFactory factory,int version){
super(context,name,factory,version);
}
public void OnCreate(SQLiteDataBase db)
db.execSQL(Crete_Provice);
db.execSQL(Create_City);
db.execSQL(Create_Country);
}
public void onUpdate(SQLiteDataBase db,int oldVersion,int newVersion){
db.execSQL("drop table if exits Book");
db.execSQL("drop table if exits Category");
onCreate(db);
}}myDbHelper=new CoolweatherOpenHelper(this,"BookStore.db",null,2);
50.天氣API
http://www.weather.com.cn/data/cityinfo/101010900.html 返回JSON數(shù)據(jù)的天氣
http://www.weather.com.cn/data/sk/101010900.html json數(shù)據(jù)
com.android.support:support-annotations:23.3.0
注釋支持庫
Retrofit retrofit = new Retrofit.Builder() //01:獲取Retrofit對象
.baseUrl("https://api.github.com/") //02采用鏈?zhǔn)浇Y(jié)構(gòu)綁定Base url
.build();//03執(zhí)行操作
GitHubService service = retrofit.create(GitHubService.class);
//04獲取API接口的實(shí)現(xiàn)類的實(shí)例對象
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://api.example.com")
.addConverterFactory(GsonConverterFactory.create())
.build();
,
這個框架的請求方式是采用的注解方式指明請求的相對路徑框架,然后參數(shù)指明具體內(nèi)容
retrofit是使用注解來體現(xiàn)HTPP請求的:
接口方法上的注解和它的參數(shù)指示了一個請求是如何處理的。
每個方法必須有一個提供請求方法和相關(guān)URL的HTTP注解
/@GET("group/{id}/users"}
Call<List<User>> groupList(@Path("id) int groupId);/
請求URL可以在方法上使用替代區(qū)塊和參數(shù)實(shí)現(xiàn)動態(tài)更新。替代區(qū)塊是由{}和包圍的字符串。對應(yīng)的@Path注解參數(shù)必須使用相同的字符串。
- 界面實(shí)現(xiàn)一般分三個部分 Activity,Fragment,Adapter
ACivity:容器
Fragment:發(fā)起請求,展示數(shù)據(jù),用戶交互
Adapter:數(shù)據(jù)的綁定/交互
54.Appliacation類的使用
Application類是Android啟動時為每個應(yīng)用程序創(chuàng)建的唯一的Application類對象,用于系統(tǒng)信息的存儲
自己定義的Application要在manifiest中注冊 name
在Android中,可以通過繼承Application類來實(shí)現(xiàn)應(yīng)用程序級的全局變量,這種全局變量方法相對靜態(tài)類更有保障,直到應(yīng)用的所有Activity全部被destory掉之后才會被釋放掉。
繼承Application類,主要重寫里面的onCreate()方法(android.app.Application包的onCreate()才是真正的Android程序的入口點(diǎn)),就是創(chuàng)建的時候,初始化變量的值。然后在整個應(yīng)用中的各個文件中就可以對該變量進(jìn)行操作了。
Volley一定要根據(jù)字符串解析
OKhttp是一個快速高效的HTTP Client,幫助實(shí)現(xiàn)連接池、
緩存等技術(shù),OKhttp扮演者傳輸層的角色
OKhttp使用okio簡化了數(shù)據(jù)的訪問和存儲,okio是java.io和java.nio的增強(qiáng)
Volley是一個簡化網(wǎng)絡(luò)任務(wù)的庫,它負(fù)責(zé)處理請求、
加載、緩存、線程、同步問題,適合頻繁交互的少量數(shù)據(jù),可以處理
JSON、圖片、緩存,支持一定程度的自定義
Volley可以輕松設(shè)置Okhhtp作為他的傳輸層