Android開發入門學習

請參閱Android入門
主要內容如下:
在這裏插入圖片描述

Android開發學習

入門

B站視頻:Android開發視頻教程-天哥在奔跑!

線性佈局、相對佈局

  1. TextView
  • 文字大小、顏色
  • 顯示不下使用…
  • 文字+icon
  • 中劃線、下劃線
  • 跑馬燈
  1. EditText 輸入控件
  • 常用屬性
  • 監聽事件
  • 製作登錄界面
  1. Radio Button 單選框
  • 常用屬性
  • 自定義樣式
  • 監聽事件
  1. CheckBox 複選框
  • 常用屬性
  • 自定義樣式
  • 監聽事件
  1. ImageView
  • Button的其他衍生控件:ToggleButton、Switch
  • 常用屬性
  • 加載網絡圖片

scaleType

  • fitXY:撐滿控件,寬高比可能發生改變
  • fitCenter:保持寬高比縮放,直至能夠完全顯示
  • centerCrop:保持寬高比縮放,直至完全覆蓋控件,裁剪顯示

列表視圖ListView

使用較少

  • 常用屬性
  • Adapter接口
  1. 滾動視圖ScrollView
  • 垂直滾動:ScrollView
  • 水平滾動:HorizontalScollView

2.1 RecyclerView(一)

RecyclerView能夠靈活實現大數據集的展示,視圖的複用管理比ListView更好,能夠顯示列表、網格、瀑布流等形式,且不同的viewHolder能夠實現item多元化的功能。

2.2 RecyclerView(二)

  • 水平滾動
  • 網格佈局

2.3 RecyclerView(三)

  • 瀑布流

2.4 RecyclerView(四)

  • 不同的ViewHolder
  • XRecyclerView: addHeadView、addFootView、下拉刷新、上拉加載
  1. WebView
  • 加載網頁,加載URL,網絡或本地assets文件夾下的html文件

  • 加載html代碼

  • Native和JavaScript相互調用

  1. 網頁的前進後退
  • webview.canGoBack()
  • webview.goBack()
  • webview.canGoForward()
  • webview.goForward()

按下返回鍵,默認是退出當前Activity,如果希望是WebView內頁面後退,則需要重寫onKeyDown()方法。
有返回值的方法,true表示我已經處理完成,不需要繼續處理。false表示還需要繼續處理。

解決ERROR_NAME_NOT_RESOLVED

  1. Check that you typed the correct site URL;
  2. Reboot your Android device;
  3. Try to open other sites. You need to understand if the ERR_NAME_NOT_RESOLVED error appears when accessing one or all sites;
  4. If you are connected to the Internet via a Wi-Fi access point (router), check whether the error appears on all devices that are connected to it, or only on single one. If there is an error on all devices, most likely there is a problem with the access point settings (try restarting your Wi-Fi router), the provider’s DNS server is unavailable, or on a web server side;
  5. There is no network connection (the cable is damaged, the router doesn’t work, your ISP has a crash, etc.);
  6. If you are using applications to perform a VPN connection, proxy server or anonymizer apps, try to disable them;
  7. Boot your Android device in safe mode. If the error in this mode doesn’t appear, the problem is most likely caused by some recently installed application.

  1. Go to menu Settings > Wi-Fi;
  2. Long press your Wi-Fi network name, then in the menu Modify this network;
  3. Mark the check box Show advanced options;
  4. Change “IP settings” to “Static”;
  5. Set the static IP for the DNS1—8.8.8.8 and DNS2—8.8.4.4 (on different versions of Android, the path and the names of the menu items may differ);

好吧,模擬器依舊沒解決

換真機

Android Studio真機調試!

UI組件之彈出組件

  1. Toast
  • Toast是一個消息提示組件
  • 設置顯示的位置
  • 自定義顯示內容(示例:添加一個圖片)
  • 簡單封裝
  1. AlertDialog
  • 默認樣式
  • 單選樣式
  • 多選樣式
  1. 自定義

  2. ProgressBar 和 ProgressDialog

  3. 自定義Dialog

  4. PopupWindow

不可不會的Activity和Fragment

1.Activity的創建三部曲

  • 新建類繼承Activity或其子類
  • 在AndroidManifest中聲明
  • 創建layout並在Activity的onCreate中設置
  1. Activity的跳轉和數據傳遞
  • 顯式跳轉和隱式跳轉
  • Activity之間的數據傳遞
  • startActivityForResult:啓動Activity,結束後返回結果
  1. Activity的4種啓動模式

Activity的android:launchMode屬性

  • standard:標準模式、默認

Activity是由任務棧管理的,每啓動一個Activity,就會被放入棧中,按返回鍵,就會從棧頂移除一個Activity。standard是默認的啓動模式,即標準模式。每啓動一個Activity,都會創建一個新的實例。

  • singleTop:Task棧頂複用模式

當要啓動的目標Activity已經位於棧頂時,不會創建新的實例,會複用棧頂的Activity,並且其onNewIntent()方法會被調用;如果目標Activity不在棧頂,則跟standard一樣創建新的實例。

  • singleTask:Task棧內複用模式

在同一個任務棧中,如果要啓動的目標Activity已經在棧中,則會複用該Activity,並調用其onNewIntent()方法,並且該Activity上面的Activity會被清除;如果棧中沒有,則會創建新的實例。

  • singleInstance:全局單例模式

全局複用,不管哪個Task棧,只要存在目標Activity,就複用。每個Activity佔有一個新的Task棧。

  1. Fragment詳解
  • Fragment有自己的生命週期
  • 依賴於Activity
  • Fragment通過getActivity()可以獲取所在的Activity;Activity通過FragmentManager的findFragmentById()或findFragmentByTag()獲取Fragment
  • Fragment和Activity是多對多關係
  • Fragment中getActivity()爲null的問題
  • 向Fragment中傳遞參數

Android啓動提示安裝失敗問題!
當啓動無顯示畫面時!

  • Fragment中getActivity()爲null的問題
  • 向Fragment傳遞參數

4.1 Fragment和Activity的通信

實現監聽事件的方法

  • 通過內部類實現
  • 通過匿名內部類實現
  • 通過事件源所在類實現
  • 通過外部類實現
  • 佈局文件中onClick屬性(針對點擊事件)

基於回調的事件處理機制

  • 回調機制與監聽機制的區別
  • 基於回調的事件傳播

源碼剖析,瞭解View事件分發

dispatchTouchEvent->setOnTouchListener->onTouchEvent
onClick/onLongClick來自onTouchEvent的處理

Handler消息處理

  • 未來某時做某事
  • 線程間通信

數據存儲

1.SharedPreferences 輕量數據存儲

  • xml文件,K-V形式
  • SharedPreferences
  • SharedPreferences.Editor

Flie

  1. Java的I/O流
  2. Android存儲概念
    內部存儲->隨應用卸載被刪除
  • /data/data/<applicationId>/shared_prefs
  • /data/data/<applicationId>/databases
  • /data/data/<applicationId>/files
  • /data/data/<applicationId>/cache
    獲取內容的方法:context.getCacheDir() context.getFilesDir()
    Android存儲->
    外部存儲:
    公有目錄Environment.getExternalStoragePublic Directory(int type)
    私有目錄/mnt/sdcard/Android/data/data/<applicationId>/cache,
    /mnt/sdcard/Android/data/data/<applicationId>/files

LocalBroadcastManager

補間動畫和屬性動畫

補間動畫沒有改變值
屬性動畫真正改變了值
補充:水波紋效果
android:foreground="?selectableItemBackground"
標籤
2020-04-27

  • 完成上述內容
  • 參考官網文檔進行 代碼補充、完善
  • 閱讀書籍《第一行代碼》

我也是小白,歡迎大家一起交流學習,如果有好的安卓架構方面的書籍或者資料歡迎推薦給我

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章